file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
listlengths
0
2
mutual_with
listlengths
0
11
ideal_premises
listlengths
0
236
proof_features
listlengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Vale.AES.PPC64LE.AES128.fsti
Vale.AES.PPC64LE.AES128.va_quick_AES128EncryptBlock
val va_quick_AES128EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ()))
val va_quick_AES128EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ()))
let va_quick_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ())) = (va_QProc (va_code_AES128EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10]) (va_wp_AES128EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock input key round_keys keys_buffer))
{ "file_name": "obj/Vale.AES.PPC64LE.AES128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 149, "start_col": 0, "start_line": 145 }
module Vale.AES.PPC64LE.AES128 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_BE_s open Vale.PPC64LE.Machine_s open Vale.PPC64LE.Memory open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.Arch.Types open Vale.AES.AES_helpers_BE #reset-options "--z3rlimit 20" //-- KeyExpansion128Stdcall val va_code_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_code val va_codegen_success_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_pbool val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall ()) va_s0 /\ va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) /\ va_state_eq va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) . let va_sM = va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion128Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ())) = (va_QProc (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) (va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion128Stdcall input_key_b output_key_expansion_b)) //-- //-- AES128EncryptBlock val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))) [@ va_qattr] let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input ==> va_k va_sM (()))) val va_wpProof_AES128EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlock input key round_keys keys_buffer va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Memory.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_helpers_BE.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.AES128.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.AES_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
input: Vale.PPC64LE.Memory.quad32 -> key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 -> round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 -> keys_buffer: Vale.PPC64LE.Memory.buffer128 -> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit (Vale.AES.PPC64LE.AES128.va_code_AES128EncryptBlock ())
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Memory.quad32", "FStar.Seq.Base.seq", "Vale.PPC64LE.Memory.nat32", "Vale.PPC64LE.Memory.buffer128", "Vale.PPC64LE.QuickCode.va_QProc", "Prims.unit", "Vale.AES.PPC64LE.AES128.va_code_AES128EncryptBlock", "Prims.Cons", "Vale.PPC64LE.QuickCode.mod_t", "Vale.PPC64LE.QuickCode.va_Mod_vec", "Vale.PPC64LE.QuickCode.va_Mod_reg", "Prims.Nil", "Vale.AES.PPC64LE.AES128.va_wp_AES128EncryptBlock", "Vale.AES.PPC64LE.AES128.va_wpProof_AES128EncryptBlock", "Vale.PPC64LE.QuickCode.va_quickCode" ]
[]
false
false
false
false
false
let va_quick_AES128EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ())) =
(va_QProc (va_code_AES128EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10]) (va_wp_AES128EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock input key round_keys keys_buffer))
false
Steel.HigherReference.fst
Steel.HigherReference.write
val write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x)
val write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x)
let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 84, "end_line": 198, "start_col": 0, "start_line": 187 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ref a -> x: a -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "FStar.Ghost.erased", "Steel.HigherReference.ref", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.PCMReference.pts_to", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "Steel.HigherReference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Memory.mem", "Steel.Memory.pure_star_interp", "Steel.Effect.Common.hp_of", "Steel.HigherReference.pts_to_raw", "Steel.HigherReference.perm_ok", "Prims.unit", "Steel.Memory.emp_unit", "Steel.PCMReference.write", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.reveal", "Steel.Effect.Common.star", "Steel.Effect.Common.pure", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "Steel.FractionalPermission.perm", "FStar.Pervasives.Native.Mktuple2", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let write (#a: Type) (#v: erased a) (r: ref a) (x: a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) =
let v_old:erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new:fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) ((RP.pts_to r v_old) `star` (pure (perm_ok full_perm))) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_4
val read_bounded_integer_4 : unit -> Tot (leaf_reader (parse_bounded_integer 4))
val read_bounded_integer_4 : unit -> Tot (leaf_reader (parse_bounded_integer 4))
let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 88, "start_col": 0, "start_line": 80 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer 4)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.decode_bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "LowStar.Endianness.load32_be_i", "LowStar.Endianness.u32", "FStar.Endianness.lemma_be_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.decode_bounded_integer_injective", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer" ]
[]
false
false
false
false
false
let read_bounded_integer_4 () =
[@@ inline_let ]let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i input pos)
false
Vale.AES.PPC64LE.AES128.fsti
Vale.AES.PPC64LE.AES128.va_quick_KeyExpansion128Stdcall
val va_quick_KeyExpansion128Stdcall (input_key_b output_key_expansion_b: buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ()))
val va_quick_KeyExpansion128Stdcall (input_key_b output_key_expansion_b: buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ()))
let va_quick_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ())) = (va_QProc (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) (va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion128Stdcall input_key_b output_key_expansion_b))
{ "file_name": "obj/Vale.AES.PPC64LE.AES128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 75, "end_line": 98, "start_col": 0, "start_line": 93 }
module Vale.AES.PPC64LE.AES128 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_BE_s open Vale.PPC64LE.Machine_s open Vale.PPC64LE.Memory open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.Arch.Types open Vale.AES.AES_helpers_BE #reset-options "--z3rlimit 20" //-- KeyExpansion128Stdcall val va_code_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_code val va_codegen_success_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_pbool val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall ()) va_s0 /\ va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) /\ va_state_eq va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) . let va_sM = va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion128Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Memory.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_helpers_BE.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.AES128.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.AES_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
input_key_b: Vale.PPC64LE.Memory.buffer128 -> output_key_expansion_b: Vale.PPC64LE.Memory.buffer128 -> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit (Vale.AES.PPC64LE.AES128.va_code_KeyExpansion128Stdcall ())
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Memory.buffer128", "Vale.PPC64LE.QuickCode.va_QProc", "Prims.unit", "Vale.AES.PPC64LE.AES128.va_code_KeyExpansion128Stdcall", "Prims.Cons", "Vale.PPC64LE.QuickCode.mod_t", "Vale.PPC64LE.QuickCode.va_Mod_vec", "Vale.PPC64LE.QuickCode.va_Mod_reg", "Vale.PPC64LE.QuickCode.va_Mod_mem_heaplet", "Vale.PPC64LE.QuickCode.va_Mod_mem", "Prims.Nil", "Vale.AES.PPC64LE.AES128.va_wp_KeyExpansion128Stdcall", "Vale.AES.PPC64LE.AES128.va_wpProof_KeyExpansion128Stdcall", "Vale.PPC64LE.QuickCode.va_quickCode" ]
[]
false
false
false
false
false
let va_quick_KeyExpansion128Stdcall (input_key_b output_key_expansion_b: buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ())) =
(va_QProc (va_code_KeyExpansion128Stdcall ()) ([ va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem ]) (va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion128Stdcall input_key_b output_key_expansion_b))
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_1
val read_bounded_integer_1 : unit -> Tot (leaf_reader (parse_bounded_integer 1))
val read_bounded_integer_1 : unit -> Tot (leaf_reader (parse_bounded_integer 1))
let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 47, "start_col": 0, "start_line": 36 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer 1)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.decode_bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.Int.Cast.uint8_to_uint32", "LowStar.Monotonic.Buffer.index", "FStar.Endianness.lemma_be_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "LowParse.Endianness.index_be_to_n", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.decode_bounded_integer_injective", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer" ]
[]
false
false
false
false
false
let read_bounded_integer_1 () =
[@@ inline_let ]let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r)
false
Vale.AES.PPC64LE.AES128.fsti
Vale.AES.PPC64LE.AES128.va_quick_AES128EncryptBlock_6way
val va_quick_AES128EncryptBlock_6way (in1 in2 in3 in4 in5 in6: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock_6way ()))
val va_quick_AES128EncryptBlock_6way (in1 in2 in3 in4 in5 in6: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock_6way ()))
let va_quick_AES128EncryptBlock_6way (in1:quad32) (in2:quad32) (in3:quad32) (in4:quad32) (in5:quad32) (in6:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock_6way ())) = (va_QProc (va_code_AES128EncryptBlock_6way ()) ([va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) (va_wp_AES128EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer))
{ "file_name": "obj/Vale.AES.PPC64LE.AES128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 92, "end_line": 221, "start_col": 0, "start_line": 215 }
module Vale.AES.PPC64LE.AES128 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_BE_s open Vale.PPC64LE.Machine_s open Vale.PPC64LE.Memory open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.Arch.Types open Vale.AES.AES_helpers_BE #reset-options "--z3rlimit 20" //-- KeyExpansion128Stdcall val va_code_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_code val va_codegen_success_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_pbool val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall ()) va_s0 /\ va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) /\ va_state_eq va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) . let va_sM = va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion128Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ())) = (va_QProc (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) (va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion128Stdcall input_key_b output_key_expansion_b)) //-- //-- AES128EncryptBlock val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))) [@ va_qattr] let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input ==> va_k va_sM (()))) val va_wpProof_AES128EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlock input key round_keys keys_buffer va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ())) = (va_QProc (va_code_AES128EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10]) (va_wp_AES128EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock input key round_keys keys_buffer)) //-- //-- AES128EncryptBlock_6way val va_code_AES128EncryptBlock_6way : va_dummy:unit -> Tot va_code val va_codegen_success_AES128EncryptBlock_6way : va_dummy:unit -> Tot va_pbool val va_lemma_AES128EncryptBlock_6way : va_b0:va_code -> va_s0:va_state -> in1:quad32 -> in2:quad32 -> in3:quad32 -> in4:quad32 -> in5:quad32 -> in6:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES128EncryptBlock_6way ()) va_s0 /\ va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4 /\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in1 /\ va_get_vec 1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in2 /\ va_get_vec 2 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in3 /\ va_get_vec 3 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in4 /\ va_get_vec 4 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in5 /\ va_get_vec 5 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in6 /\ va_state_eq va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0))))))))))) [@ va_qattr] let va_wp_AES128EncryptBlock_6way (in1:quad32) (in2:quad32) (in3:quad32) (in4:quad32) (in5:quad32) (in6:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4 /\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) . let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in1 /\ va_get_vec 1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in2 /\ va_get_vec 2 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in3 /\ va_get_vec 3 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in4 /\ va_get_vec 4 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in5 /\ va_get_vec 5 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in6 ==> va_k va_sM (()))) val va_wpProof_AES128EncryptBlock_6way : in1:quad32 -> in2:quad32 -> in3:quad32 -> in4:quad32 -> in5:quad32 -> in6:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlock_6way ()) ([va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Memory.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_helpers_BE.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.AES128.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.AES_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
in1: Vale.PPC64LE.Memory.quad32 -> in2: Vale.PPC64LE.Memory.quad32 -> in3: Vale.PPC64LE.Memory.quad32 -> in4: Vale.PPC64LE.Memory.quad32 -> in5: Vale.PPC64LE.Memory.quad32 -> in6: Vale.PPC64LE.Memory.quad32 -> key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 -> round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 -> keys_buffer: Vale.PPC64LE.Memory.buffer128 -> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit (Vale.AES.PPC64LE.AES128.va_code_AES128EncryptBlock_6way ())
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Memory.quad32", "FStar.Seq.Base.seq", "Vale.PPC64LE.Memory.nat32", "Vale.PPC64LE.Memory.buffer128", "Vale.PPC64LE.QuickCode.va_QProc", "Prims.unit", "Vale.AES.PPC64LE.AES128.va_code_AES128EncryptBlock_6way", "Prims.Cons", "Vale.PPC64LE.QuickCode.mod_t", "Vale.PPC64LE.QuickCode.va_Mod_vec", "Vale.PPC64LE.QuickCode.va_Mod_reg", "Prims.Nil", "Vale.AES.PPC64LE.AES128.va_wp_AES128EncryptBlock_6way", "Vale.AES.PPC64LE.AES128.va_wpProof_AES128EncryptBlock_6way", "Vale.PPC64LE.QuickCode.va_quickCode" ]
[]
false
false
false
false
false
let va_quick_AES128EncryptBlock_6way (in1 in2 in3 in4 in5 in6: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock_6way ())) =
(va_QProc (va_code_AES128EncryptBlock_6way ()) ([ va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10 ]) (va_wp_AES128EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer))
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_2
val read_bounded_integer_2 : unit -> Tot (leaf_reader (parse_bounded_integer 2))
val read_bounded_integer_2 : unit -> Tot (leaf_reader (parse_bounded_integer 2))
let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 58, "start_col": 0, "start_line": 49 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer 2)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.decode_bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.Int.Cast.uint16_to_uint32", "FStar.Endianness.lemma_be_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "LowStar.Endianness.u16", "LowStar.Endianness.load16_be_i", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.decode_bounded_integer_injective", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer" ]
[]
false
false
false
false
false
let read_bounded_integer_2 () =
[@@ inline_let ]let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_1
val write_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val write_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 36, "end_line": 176, "start_col": 0, "start_line": 174 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.write_bounded_int32'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32", "LowParse.Spec.BoundedInt.serialize_bounded_int32" ]
[]
false
false
false
false
false
let write_bounded_int32_1 min32 max32 =
write_bounded_int32' min32 max32 1
false
Vale.AES.PPC64LE.AES128.fsti
Vale.AES.PPC64LE.AES128.va_wp_AES128EncryptBlock
val va_wp_AES128EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_AES128EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.AES128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 135, "start_col": 0, "start_line": 123 }
module Vale.AES.PPC64LE.AES128 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_BE_s open Vale.PPC64LE.Machine_s open Vale.PPC64LE.Memory open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.Arch.Types open Vale.AES.AES_helpers_BE #reset-options "--z3rlimit 20" //-- KeyExpansion128Stdcall val va_code_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_code val va_codegen_success_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_pbool val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall ()) va_s0 /\ va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) /\ va_state_eq va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) . let va_sM = va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion128Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ())) = (va_QProc (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) (va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion128Stdcall input_key_b output_key_expansion_b)) //-- //-- AES128EncryptBlock val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0))))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Memory.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_helpers_BE.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.AES128.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.AES_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
input: Vale.PPC64LE.Memory.quad32 -> key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 -> round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 -> keys_buffer: Vale.PPC64LE.Memory.buffer128 -> va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Memory.quad32", "FStar.Seq.Base.seq", "Vale.PPC64LE.Memory.nat32", "Vale.PPC64LE.Memory.buffer128", "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Vale.AES.AES_BE_s.is_aes_key_word", "Vale.AES.AES_common_s.AES_128", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "Vale.AES.AES_BE_s.key_to_round_keys_word", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Decls.va_get_vec", "Vale.PPC64LE.Decls.va_get_reg", "Vale.PPC64LE.Memory.buffer_addr", "Vale.PPC64LE.Memory.vuint128", "Vale.PPC64LE.Decls.va_get_mem_heaplet", "Vale.PPC64LE.Decls.validSrcAddrs128", "Vale.PPC64LE.Decls.va_get_mem_layout", "Vale.Arch.HeapTypes_s.Secret", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.PPC64LE.Decls.buffer128_read", "FStar.Seq.Base.index", "Vale.PPC64LE.Memory.nat64", "Vale.AES.AES_BE_s.aes_encrypt_word", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_vec", "Vale.PPC64LE.Decls.va_upd_reg" ]
[]
false
false
false
true
true
let va_wp_AES128EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i: nat). i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v2: quad32). let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input ==> va_k va_sM (())))
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_2
val write_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val write_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 36, "end_line": 180, "start_col": 0, "start_line": 178 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.write_bounded_int32'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32", "LowParse.Spec.BoundedInt.serialize_bounded_int32" ]
[]
false
false
false
false
false
let write_bounded_int32_2 min32 max32 =
write_bounded_int32' min32 max32 2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32'
val write_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val write_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 172, "start_col": 0, "start_line": 156 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> sz: Prims.nat{sz == LowParse.Spec.BoundedInt.log256' (FStar.UInt32.v max32)} -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.nat", "Prims.eq2", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.write_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.BoundedInt.serialize_bounded_integer", "LowParse.Low.Combinators.write_filter", "LowParse.Low.BoundedInt.write_bounded_integer", "LowParse.Spec.BoundedInt.bounded_int32", "FStar.UInt.uint_t", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32", "LowParse.Spec.BoundedInt.serialize_bounded_int32" ]
[]
false
false
false
false
false
let write_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) =
[@@ inline_let ]let min = U32.v min32 in [@@ inline_let ]let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) ()
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_3
val write_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val write_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 36, "end_line": 184, "start_col": 0, "start_line": 182 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.write_bounded_int32'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32", "LowParse.Spec.BoundedInt.serialize_bounded_int32" ]
[]
false
false
false
false
false
let write_bounded_int32_3 min32 max32 =
write_bounded_int32' min32 max32 3
false
Vale.AES.PPC64LE.AES128.fsti
Vale.AES.PPC64LE.AES128.va_wp_AES128EncryptBlock_6way
val va_wp_AES128EncryptBlock_6way (in1 in2 in3 in4 in5 in6: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_AES128EncryptBlock_6way (in1 in2 in3 in4 in5 in6: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_AES128EncryptBlock_6way (in1:quad32) (in2:quad32) (in3:quad32) (in4:quad32) (in5:quad32) (in6:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4 /\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) . let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in1 /\ va_get_vec 1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in2 /\ va_get_vec 2 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in3 /\ va_get_vec 3 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in4 /\ va_get_vec 4 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in5 /\ va_get_vec 5 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in6 ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.AES128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 203, "start_col": 0, "start_line": 182 }
module Vale.AES.PPC64LE.AES128 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_BE_s open Vale.PPC64LE.Machine_s open Vale.PPC64LE.Memory open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.Arch.Types open Vale.AES.AES_helpers_BE #reset-options "--z3rlimit 20" //-- KeyExpansion128Stdcall val va_code_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_code val va_codegen_success_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_pbool val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall ()) va_s0 /\ va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) /\ va_state_eq va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) . let va_sM = va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion128Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall ())) = (va_QProc (va_code_KeyExpansion128Stdcall ()) ([va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) (va_wp_KeyExpansion128Stdcall input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion128Stdcall input_key_b output_key_expansion_b)) //-- //-- AES128EncryptBlock val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))) [@ va_qattr] let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key input ==> va_k va_sM (()))) val va_wpProof_AES128EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlock input key round_keys keys_buffer va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ())) = (va_QProc (va_code_AES128EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10]) (va_wp_AES128EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock input key round_keys keys_buffer)) //-- //-- AES128EncryptBlock_6way val va_code_AES128EncryptBlock_6way : va_dummy:unit -> Tot va_code val va_codegen_success_AES128EncryptBlock_6way : va_dummy:unit -> Tot va_pbool val va_lemma_AES128EncryptBlock_6way : va_b0:va_code -> va_s0:va_state -> in1:quad32 -> in2:quad32 -> in3:quad32 -> in4:quad32 -> in5:quad32 -> in6:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES128EncryptBlock_6way ()) va_s0 /\ va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4 /\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in1 /\ va_get_vec 1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in2 /\ va_get_vec 2 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in3 /\ va_get_vec 3 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in4 /\ va_get_vec 4 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in5 /\ va_get_vec 5 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in6 /\ va_state_eq va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Memory.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_helpers_BE.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.AES128.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.AES_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
in1: Vale.PPC64LE.Memory.quad32 -> in2: Vale.PPC64LE.Memory.quad32 -> in3: Vale.PPC64LE.Memory.quad32 -> in4: Vale.PPC64LE.Memory.quad32 -> in5: Vale.PPC64LE.Memory.quad32 -> in6: Vale.PPC64LE.Memory.quad32 -> key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 -> round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 -> keys_buffer: Vale.PPC64LE.Memory.buffer128 -> va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Memory.quad32", "FStar.Seq.Base.seq", "Vale.PPC64LE.Memory.nat32", "Vale.PPC64LE.Memory.buffer128", "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Vale.AES.AES_BE_s.is_aes_key_word", "Vale.AES.AES_common_s.AES_128", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "Vale.AES.AES_BE_s.key_to_round_keys_word", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Decls.va_get_vec", "Vale.PPC64LE.Decls.va_get_reg", "Vale.PPC64LE.Memory.buffer_addr", "Vale.PPC64LE.Memory.vuint128", "Vale.PPC64LE.Decls.va_get_mem_heaplet", "Vale.PPC64LE.Decls.validSrcAddrs128", "Vale.PPC64LE.Decls.va_get_mem_layout", "Vale.Arch.HeapTypes_s.Secret", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.PPC64LE.Decls.buffer128_read", "FStar.Seq.Base.index", "Vale.PPC64LE.Memory.nat64", "Vale.AES.AES_BE_s.aes_encrypt_word", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_vec", "Vale.PPC64LE.Decls.va_upd_reg" ]
[]
false
false
false
true
true
let va_wp_AES128EncryptBlock_6way (in1 in2 in3 in4 in5 in6: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_128 key /\ FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key /\ va_get_vec 0 va_s0 == in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4 /\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i: nat). i < 11 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v1: quad32) (va_x_v2: quad32) (va_x_v3: quad32) (va_x_v4: quad32) (va_x_v5: quad32) (va_x_v6: quad32). let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in1 /\ va_get_vec 1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in2 /\ va_get_vec 2 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in3 /\ va_get_vec 3 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in4 /\ va_get_vec 4 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in5 /\ va_get_vec 5 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_128 key in6 ==> va_k va_sM (())))
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_1
val read_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val read_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 212, "start_col": 0, "start_line": 210 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.read_bounded_int32'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let read_bounded_int32_1 min32 max32 =
read_bounded_int32' min32 max32 1
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.serialize32_bounded_integer_1
val serialize32_bounded_integer_1 : unit -> Tot (serializer32 (serialize_bounded_integer 1))
val serialize32_bounded_integer_1 : unit -> Tot (serializer32 (serialize_bounded_integer 1))
let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 108, "start_col": 0, "start_line": 103 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_integer 1)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Spec.BoundedInt.bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.mbuffer_upd", "FStar.Ghost.hide", "Prims.nat", "FStar.UInt32.v", "Prims.op_Addition", "FStar.Int.Cast.uint32_to_uint8", "LowParse.Endianness.index_n_to_be", "LowParse.Spec.BoundedInt.bounded_integer_prop_equiv" ]
[]
false
false
false
false
false
let serialize32_bounded_integer_1 () =
fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul
false
Vale.AES.PPC64LE.AES128.fsti
Vale.AES.PPC64LE.AES128.va_wp_KeyExpansion128Stdcall
val va_wp_KeyExpansion128Stdcall (input_key_b output_key_expansion_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_KeyExpansion128Stdcall (input_key_b output_key_expansion_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_KeyExpansion128Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) . let va_sM = va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.AES128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 82, "start_col": 0, "start_line": 55 }
module Vale.AES.PPC64LE.AES128 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_BE_s open Vale.PPC64LE.Machine_s open Vale.PPC64LE.Memory open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.Arch.Types open Vale.AES.AES_helpers_BE #reset-options "--z3rlimit 20" //-- KeyExpansion128Stdcall val va_code_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_code val va_codegen_success_KeyExpansion128Stdcall : va_dummy:unit -> Tot va_pbool val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall ()) va_s0 /\ va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) /\ va_state_eq va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Memory.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_helpers_BE.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.AES128.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.AES_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
input_key_b: Vale.PPC64LE.Memory.buffer128 -> output_key_expansion_b: Vale.PPC64LE.Memory.buffer128 -> va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Memory.buffer128", "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Vale.PPC64LE.Decls.validSrcAddrs128", "Vale.PPC64LE.Decls.va_get_mem_heaplet", "Vale.PPC64LE.Decls.va_get_reg", "Vale.PPC64LE.Decls.va_get_mem_layout", "Vale.Arch.HeapTypes_s.Secret", "Vale.PPC64LE.Decls.validDstAddrs128", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.AES.AES_helpers_BE.be_quad32_to_seq", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.PPC64LE.Decls.buffer128_read", "Prims.l_Forall", "Vale.PPC64LE.InsBasic.vale_heap", "Vale.PPC64LE.Memory.nat64", "Vale.PPC64LE.Memory.quad32", "Prims.l_imp", "Vale.PPC64LE.Decls.modifies_buffer128", "Prims.int", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Def.Types_s.quad32", "Vale.AES.AES_BE_s.key_to_round_keys_word", "Vale.AES.AES_common_s.AES_128", "Prims.op_LessThanOrEqual", "Prims.eq2", "FStar.Seq.Base.index", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_vec", "Vale.PPC64LE.Decls.va_upd_reg", "Vale.PPC64LE.Decls.va_upd_mem_heaplet", "Vale.PPC64LE.Decls.va_upd_mem" ]
[]
false
false
false
true
true
let va_wp_KeyExpansion128Stdcall (input_key_b output_key_expansion_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0) output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem: vale_heap) (va_x_heap1: vale_heap) (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v1: quad32) (va_x_v2: quad32) (va_x_v3: quad32) (va_x_v4: quad32). let va_sM = va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM) input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) = Vale.AES.AES_helpers_BE.be_quad32_to_seq (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j. {:pattern (reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))} 0 <= j /\ j <= 10 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_128 key) j)) ==> va_k va_sM (())))
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_2
val read_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val read_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 216, "start_col": 0, "start_line": 214 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.read_bounded_int32'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let read_bounded_int32_2 min32 max32 =
read_bounded_int32' min32 max32 2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_3
val read_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val read_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 220, "start_col": 0, "start_line": 218 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.read_bounded_int32'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let read_bounded_int32_3 min32 max32 =
read_bounded_int32' min32 max32 3
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_4
val write_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val write_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 36, "end_line": 188, "start_col": 0, "start_line": 186 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.write_bounded_int32'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32", "LowParse.Spec.BoundedInt.serialize_bounded_int32" ]
[]
false
false
false
false
false
let write_bounded_int32_4 min32 max32 =
write_bounded_int32' min32 max32 4
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_4
val read_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val read_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 224, "start_col": 0, "start_line": 222 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.read_bounded_int32'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let read_bounded_int32_4 min32 max32 =
read_bounded_int32' min32 max32 4
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.mul256
val mul256 (x: U16.t) : Tot (y: U32.t{U32.v y == 256 `Prims.op_Multiply` (U16.v x)})
val mul256 (x: U16.t) : Tot (y: U32.t{U32.v y == 256 `Prims.op_Multiply` (U16.v x)})
let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 46, "end_line": 26, "start_col": 0, "start_line": 18 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt16.t -> y: FStar.UInt32.t{FStar.UInt32.v y == 256 * FStar.UInt16.v x}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt16.t", "FStar.UInt32.shift_left", "FStar.Int.Cast.uint16_to_uint32", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.UInt.shift_left_value_lemma", "FStar.UInt16.v", "FStar.Math.Lemmas.small_mod", "Prims.op_Multiply", "Prims.pow2", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.pow2_lt_compat", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.UInt32.t", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let mul256 (x: U16.t) : Tot (y: U32.t{U32.v y == 256 `Prims.op_Multiply` (U16.v x)}) =
assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod ((U16.v x) `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; (Cast.uint16_to_uint32 x) `U32.shift_left` 8ul
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32'
val read_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val read_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 208, "start_col": 0, "start_line": 191 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> sz: Prims.nat{sz == LowParse.Spec.BoundedInt.log256' (FStar.UInt32.v max32)} -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.nat", "Prims.eq2", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.read_inline_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Low.Combinators.read_filter", "LowParse.Low.BoundedInt.read_bounded_integer", "FStar.UInt.uint_t", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let read_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) =
[@@ inline_let ]let min = U32.v min32 in [@@ inline_let ]let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) ()
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_4
val validate_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val validate_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 261, "start_col": 0, "start_line": 259 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.validate_bounded_int32'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let validate_bounded_int32_4 min32 max32 =
validate_bounded_int32' min32 max32 4
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_1
val jump_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val jump_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 283, "start_col": 0, "start_line": 281 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.jump_bounded_int32'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let jump_bounded_int32_1 min32 max32 =
jump_bounded_int32' min32 max32 1
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_3
val validate_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val validate_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 257, "start_col": 0, "start_line": 255 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.validate_bounded_int32'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let validate_bounded_int32_3 min32 max32 =
validate_bounded_int32' min32 max32 3
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32'
val validate_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val validate_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 245, "start_col": 0, "start_line": 227 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> sz: Prims.nat{sz == LowParse.Spec.BoundedInt.log256' (FStar.UInt32.v max32)} -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.nat", "Prims.eq2", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.validate_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Low.Combinators.validate_filter", "LowParse.Low.BoundedInt.validate_bounded_integer", "LowParse.Low.BoundedInt.read_bounded_integer", "Prims.op_Negation", "Prims.op_BarBar", "FStar.UInt32.lt", "Prims.bool", "FStar.UInt.uint_t", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let validate_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) =
[@@ inline_let ]let min = U32.v min32 in [@@ inline_let ]let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x))) (fun x -> (x <: bounded_int32 min max)) ()
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_2
val validate_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val validate_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 253, "start_col": 0, "start_line": 251 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.validate_bounded_int32'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let validate_bounded_int32_2 min32 max32 =
validate_bounded_int32' min32 max32 2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_1
val validate_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val validate_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 249, "start_col": 0, "start_line": 247 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.validate_bounded_int32'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let validate_bounded_int32_1 min32 max32 =
validate_bounded_int32' min32 max32 1
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.serialize32_bounded_integer_2
val serialize32_bounded_integer_2 : unit -> Tot (serializer32 (serialize_bounded_integer 2))
val serialize32_bounded_integer_2 : unit -> Tot (serializer32 (serialize_bounded_integer 2))
let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 119, "start_col": 0, "start_line": 110 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_integer 2)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Spec.BoundedInt.bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "LowParse.Low.Endianness.store_post_modifies", "FStar.UInt32.v", "FStar.Seq.Base.seq", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt16.n", "FStar.Endianness.be_to_n", "FStar.UInt16.v", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Endianness.store16_be_i", "LowParse.Low.Endianness.writable_store_pre", "FStar.UInt16.t", "Prims.op_Equality", "Prims.op_Modulus", "Prims.pow2", "FStar.Int.Cast.uint32_to_uint16", "LowParse.Spec.BoundedInt.bounded_integer_prop_equiv" ]
[]
false
false
false
false
false
let serialize32_bounded_integer_2 () =
fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32'
val jump_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val jump_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 279, "start_col": 0, "start_line": 264 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> sz: Prims.nat{sz == LowParse.Spec.BoundedInt.log256' (FStar.UInt32.v max32)} -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.nat", "Prims.eq2", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.jump_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Low.Combinators.jump_filter", "LowParse.Low.BoundedInt.jump_bounded_integer", "FStar.UInt.uint_t", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let jump_bounded_int32' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) =
[@@ inline_let ]let min = U32.v min32 in [@@ inline_let ]let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) ()
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_ct
val read_bounded_integer_ct (i: U32.t { 1 <= U32.v i /\ U32.v i <= 4 }) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : HST.Stack (bounded_integer (U32.v i)) (requires (fun h -> live_slice h sl /\ U32.v pos + 4 <= U32.v sl.len )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_content (parse_bounded_integer (U32.v i)) h sl pos res ))
val read_bounded_integer_ct (i: U32.t { 1 <= U32.v i /\ U32.v i <= 4 }) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : HST.Stack (bounded_integer (U32.v i)) (requires (fun h -> live_slice h sl /\ U32.v pos + 4 <= U32.v sl.len )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_content (parse_bounded_integer (U32.v i)) h sl pos res ))
let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 72, "end_line": 101, "start_col": 0, "start_line": 90 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: FStar.UInt32.t{1 <= FStar.UInt32.v i /\ FStar.UInt32.v i <= 4} -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack (LowParse.Spec.BoundedInt.bounded_integer (FStar.UInt32.v i))
FStar.HyperStack.ST.Stack
[]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield_gen", "LowParse.BitFields.uint32", "FStar.UInt32.mul", "FStar.UInt32.__uint_to_t", "FStar.UInt32.sub", "LowParse.Spec.BoundedInt.bounded_integer", "LowStar.Endianness.u32", "LowStar.Endianness.load32_be_i", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "Prims.unit", "LowParse.Endianness.BitFields.bitfield_be_to_n_slice", "FStar.Seq.Base.slice", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.Int.parse_u32_spec", "LowParse.Spec.BoundedInt.decode_bounded_integer_injective", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Int.parse_u32_kind", "LowParse.Spec.Int.parse_u32", "LowParse.Low.Base.valid_total_constant_size", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let read_bounded_integer_ct i #rrel #rel sl pos =
let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_2
val jump_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val jump_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 287, "start_col": 0, "start_line": 285 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.jump_bounded_int32'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let jump_bounded_int32_2 min32 max32 =
jump_bounded_int32' min32 max32 2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_3
val read_bounded_integer_3 : unit -> Tot (leaf_reader (parse_bounded_integer 3))
val read_bounded_integer_3 : unit -> Tot (leaf_reader (parse_bounded_integer 3))
let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 76, "start_col": 0, "start_line": 62 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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" }
false
_: Prims.unit -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer 3)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.decode_bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.UInt32.add", "FStar.Int.Cast.uint8_to_uint32", "LowParse.Low.BoundedInt.mul256", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.pow2", "FStar.Endianness.lemma_be_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "LowStar.Endianness.u16", "LowStar.Endianness.load16_be_i", "LowStar.Monotonic.Buffer.index", "FStar.Endianness.reveal_be_to_n", "FStar.Seq.Properties.lemma_split", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.decode_bounded_integer_injective", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer" ]
[]
false
false
false
false
false
let read_bounded_integer_3 () =
[@@ inline_let ]let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); (Cast.uint8_to_uint32 lo) `U32.add` (mul256 hi))
false
LocalState.fst
LocalState.t2
val t2: Prims.unit -> Tac unit
val t2: Prims.unit -> Tac unit
let t2 () : Tac unit = fail "always fail"
{ "file_name": "examples/tactics/LocalState.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 27, "start_col": 0, "start_line": 27 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LocalState open FStar.Tactics.V2 type st1 = { x : int; y : int; } type st2 = int -> int
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LocalState.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.fail" ]
[]
false
true
false
false
false
let t2 () : Tac unit =
fail "always fail"
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.serialize32_bounded_integer_4
val serialize32_bounded_integer_4 : unit -> Tot (serializer32 (serialize_bounded_integer 4))
val serialize32_bounded_integer_4 : unit -> Tot (serializer32 (serialize_bounded_integer 4))
let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 153, "start_col": 0, "start_line": 145 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_integer 4)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Spec.BoundedInt.bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "LowParse.Low.Endianness.store_post_modifies", "FStar.UInt32.v", "FStar.Seq.Base.seq", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Endianness.be_to_n", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Endianness.store32_be_i", "LowParse.Low.Endianness.writable_store_pre", "LowParse.Spec.BoundedInt.bounded_integer_prop_equiv" ]
[]
false
false
false
false
false
let serialize32_bounded_integer_4 () =
fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.gaccessor_clens_dsum_payload_no_lookahead
val gaccessor_clens_dsum_payload_no_lookahead (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl': bytes) : Lemma (requires ((parse_dsum_kind kt t f ku).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ no_lookahead_on_precond (parse_dsum t p f g) sl sl')) (ensures (gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl'))
val gaccessor_clens_dsum_payload_no_lookahead (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl': bytes) : Lemma (requires ((parse_dsum_kind kt t f ku).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ no_lookahead_on_precond (parse_dsum t p f g) sl sl')) (ensures (gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl'))
let gaccessor_clens_dsum_payload_no_lookahead (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl' : bytes) : Lemma (requires ( (parse_dsum_kind kt t f ku).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ no_lookahead_on_precond (parse_dsum t p f g) sl sl' )) (ensures ( gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl' )) = parse_dsum_eq3 t p f g sl; parse_dsum_eq3 t p f g sl'; parse_strong_prefix (parse_dsum t p f g) sl sl' ; parse_injective p sl sl'
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 26, "end_line": 1887, "start_col": 0, "start_line": 1865 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; } let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) inline_for_extraction let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) = accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) let clens_sum_payload (s: sum) (k: sum_key s) : Tot (clens (sum_type s) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_type s) -> sum_tag_of_data s x == k); clens_get = (fun (x: sum_type s) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (sum_tag_of_data s x == k)) (ensures (fun _ -> True))); } #push-options "--z3rlimit 32" let gaccessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = fun (input: bytes) -> parse_sum_eq'' t p pc input; let res = match parse p input with | Some (_, consumed) -> synth_sum_case_inverse t k; synth_sum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); (consumed) | _ -> 0 // dummy in (res <: (res: _ { gaccessor_post' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) input res } )) #push-options "--z3rlimit 64" let gaccessor_clens_sum_payload_injective (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ injective_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_injective (parse_sum t p pc) sl sl' ; parse_injective p sl sl' #pop-options let gaccessor_clens_sum_payload_no_lookahead (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( (parse_sum_kind kt t pc).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ no_lookahead_on_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_strong_prefix (parse_sum t p pc) sl sl' ; parse_injective p sl sl' let gaccessor_clens_sum_payload (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_injective t p pc k x)); Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_no_lookahead t p pc k x)); gaccessor_prop_equiv (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) (gaccessor_clens_sum_payload' t p pc k); gaccessor_clens_sum_payload' t p pc k inline_for_extraction let accessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_sum t p pc) h input pos /\ (clens_sum_payload t k).clens_cond (contents (parse_sum t p pc) h input pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h (gaccessor_clens_sum_payload t p pc k) input pos )) = let h = HST.get () in [@inline_let] let _ = let pos' = get_valid_pos (parse_sum t p pc) h input pos in let large = bytes_of_slice_from h input pos in slice_access_eq h (gaccessor_clens_sum_payload t p pc k) input pos; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq'' t p pc large; valid_facts p h input pos in j input pos #pop-options inline_for_extraction let accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k)) = fun #rrel #rel -> accessor_clens_sum_payload' t j pc k #rrel #rel let clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_cases s k) -> True); clens_get = (fun (x: sum_cases s k) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (True)) (ensures (fun _ -> True))); } let gaccessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum_cases' t pc k) (dsnd (pc k)) (clens_sum_cases_payload t k)) = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); gaccessor_ext (gaccessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let accessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_cases_payload t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) () in accessor_ext (accessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let validate_dsum_cases_t (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot Type = validator (parse_dsum_cases' s f g x) let validate_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2 : validate_dsum_cases_t s f g x) : GTot Type0 = True inline_for_extraction let validate_dsum_cases_if' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (cond: bool) (ift: (cond_true cond -> Tot (validate_dsum_cases_t s f g x))) (iff: (cond_false cond -> Tot (validate_dsum_cases_t s f g x))) : Tot (validate_dsum_cases_t s f g x) = fun #rrel #rel input len -> if cond then (ift () <: validate_dsum_cases_t s f g x) input len else (iff () <: validate_dsum_cases_t s f g x) input len inline_for_extraction let validate_dsum_cases_if (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot (if_combinator _ (validate_dsum_cases_eq s f g x)) = validate_dsum_cases_if' s f g x inline_for_extraction let validate_dsum_cases' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (x: dsum_key s) : Tot (validate_dsum_cases_t s f g x) = [@inline_let] let _ = synth_dsum_case_injective s x in match x with | Known x' -> validate_synth (f' x') (synth_dsum_case s (Known x')) () <: validator (parse_dsum_cases' s f g x) | Unknown x' -> validate_synth g' (synth_dsum_case s (Unknown x')) () <: validator (parse_dsum_cases' s f g x) inline_for_extraction let validate_dsum_cases'_destr (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (destr: dep_enum_destr _ (fun k -> validate_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (validate_dsum_cases_t s f g x) = fun #rrel #rel input pos -> match x with | Known k -> destr _ (fun k -> validate_dsum_cases_if s f g (Known k)) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> validate_dsum_cases' s f f' g' (Known k)) k input pos | Unknown r -> validate_dsum_cases' s f f' g' (Unknown r) input pos inline_for_extraction let validate_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (destr: dep_enum_destr _ (fun k -> validate_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (validator (parse_dsum_cases s f g x)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_dsum_cases' s f g x) h input (uint64_to_uint32 pos); valid_facts (parse_dsum_cases s f g x) h input (uint64_to_uint32 pos); parse_dsum_cases_eq' s f g x (bytes_of_slice_from h input (uint64_to_uint32 pos)) in validate_dsum_cases'_destr s f f' g' destr x input pos #push-options "--z3rlimit 40" inline_for_extraction let validate_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (v: validator p) (p32: leaf_reader p) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (validator (dsnd (f x)))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (g32: validator g) (destr: dep_maybe_enum_destr_t (dsum_enum t) (validate_dsum_cases_t t f g)) : Tot (validator (parse_dsum t p f g)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_dsum_eq' t p f g (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_dsum t p f g) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let pos_after_tag = v input pos in if is_error pos_after_tag then pos_after_tag else let tg = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts (parse_dsum_cases' t f g (maybe_enum_key_of_repr (dsum_enum t) tg)) h input (uint64_to_uint32 pos_after_tag) in destr (validate_dsum_cases_eq t f g) (validate_dsum_cases_if t f g) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_dsum_cases' t f f32 g32) tg input pos_after_tag #pop-options #reset-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" let valid_dsum_intro_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ ( let Known k = k' in valid (dsnd (f k)) h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos) )))) (ensures ( let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload) )) = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts (dsnd (f k)) h input pos_payload; valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos) let valid_dsum_intro_unknown (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Unknown? k' /\ valid g h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos) ))) (ensures ( let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Unknown r) (contents g h input pos_payload)) (get_valid_pos g h input pos_payload) )) = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts g h input pos_payload; valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos) #reset-options inline_for_extraction let finalize_dsum_case_known (t: dsum) (#kt: parser_kind) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (destr: enum_repr_of_key'_t (dsum_enum t)) (k: dsum_known_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (dsum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (f k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (dsum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_dsum t p f g) h' input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload) )) = let pos1 = write_enum_key w (dsum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_facts (parse_enum_key p (dsum_enum t)) h input pos; valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let sq = bytes_of_slice_from h input pos in parse_enum_key_eq p (dsum_enum t) sq; parse_maybe_enum_key_eq p (dsum_enum t) sq; valid_dsum_intro_known h t p f g input pos in () inline_for_extraction let finalize_dsum_case_unknown (t: dsum) (#kt: parser_kind) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (r: unknown_enum_repr (dsum_enum t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length s r in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid g h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length s r in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_dsum t p f g) h' input pos (synth_dsum_case t (Unknown r) (contents g h input pos_payload)) (get_valid_pos g h input pos_payload) )) = let pos1 = w r input pos in let h = HST.get () in [@inline_let] let _ = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; valid_facts p h input pos; let sq = bytes_of_slice_from h input pos in parse_maybe_enum_key_eq p (dsum_enum t) sq; valid_dsum_intro_unknown h t p f g input pos in () let valid_dsum_elim_tag (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_dsum t p f g) h input pos )) (ensures ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ contents (parse_maybe_enum_key p (dsum_enum t)) h input pos == dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos) )) = let _ = parse_dsum_eq_ t p f g (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_dsum t p f g) h input pos in let _ = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos in () inline_for_extraction let read_dsum_tag (t: dsum) (#kt: parser_kind) (#p: parser kt (dsum_repr_type t)) (p32: leaf_reader p) (destr: maybe_enum_destr_t (maybe_enum_key (dsum_enum t)) (dsum_enum t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (dsum_key t) (requires (fun h -> valid (parse_dsum t p f g) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_dsum_elim_tag h t p f g input pos in read_maybe_enum_key p32 (dsum_enum t) destr input pos #push-options "--z3rlimit 32" let valid_dsum_elim_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_dsum t p f g) h input pos /\ Known? (dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos)) )) (ensures ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ ( let Known k = k' in valid (dsnd (f k)) h input pos_payload /\ valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload) )))) = valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos); valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts (dsnd (f k)) h input pos_payload #pop-options let valid_dsum_elim_unknown (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_dsum t p f g) h input pos /\ Unknown? (dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos)) )) (ensures ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in Unknown? k' /\ ( let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid g h input pos_payload /\ valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Unknown r) (contents g h input pos_payload)) (get_valid_pos g h input pos_payload) )))) = valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos); valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts g h input pos_payload inline_for_extraction let jump_dsum_cases_t (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot Type = jumper (parse_dsum_cases' s f g x) let jump_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2 : jump_dsum_cases_t s f g x) : GTot Type0 = True inline_for_extraction let jump_dsum_cases_if' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (cond: bool) (ift: (cond_true cond -> Tot (jump_dsum_cases_t s f g x))) (iff: (cond_false cond -> Tot (jump_dsum_cases_t s f g x))) : Tot (jump_dsum_cases_t s f g x) = fun #rrel #rel input len -> if cond then (ift () <: jump_dsum_cases_t s f g x) input len else (iff () <: jump_dsum_cases_t s f g x) input len inline_for_extraction let jump_dsum_cases_if (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot (if_combinator _ (jump_dsum_cases_eq s f g x)) = jump_dsum_cases_if' s f g x inline_for_extraction let jump_dsum_cases' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (jumper (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : jumper g) (x: dsum_key s) : Tot (jump_dsum_cases_t s f g x) = synth_dsum_case_injective s x; match x with | Known x' -> jump_synth (f' x') (synth_dsum_case s (Known x')) () <: jumper (parse_dsum_cases' s f g x) | Unknown x' -> jump_synth g' (synth_dsum_case s (Unknown x')) () <: jumper (parse_dsum_cases' s f g x) inline_for_extraction let jump_dsum_cases'_destr (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (jumper (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : jumper g) (destr: dep_enum_destr _ (fun k -> jump_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (jump_dsum_cases_t s f g x) = fun #rrel #rel input pos -> match x with | Known k -> destr _ (fun k -> jump_dsum_cases_if s f g (Known k)) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> jump_dsum_cases' s f f' g' (Known k)) k input pos | Unknown r -> jump_dsum_cases' s f f' g' (Unknown r) input pos inline_for_extraction let jump_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (jumper (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : jumper g) (destr: dep_enum_destr _ (fun k -> jump_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (jumper (parse_dsum_cases s f g x)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_dsum_cases' s f g x) h input pos; valid_facts (parse_dsum_cases s f g x) h input pos; parse_dsum_cases_eq' s f g x (bytes_of_slice_from h input pos) in jump_dsum_cases'_destr s f f' g' destr x input pos #push-options "--z3rlimit 16" inline_for_extraction let jump_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (jumper (dsnd (f x)))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (g32: jumper g) (destr: dep_maybe_enum_destr_t (dsum_enum t) (jump_dsum_cases_t t f g)) : Tot (jumper (parse_dsum t p f g)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_dsum_eq' t p f g (bytes_of_slice_from h input pos) in [@inline_let] let _ = valid_facts (parse_dsum t p f g) h input pos in [@inline_let] let _ = valid_facts p h input pos in let pos_after_tag = v input pos in let tg = p32 input pos in [@inline_let] let _ = valid_facts (parse_dsum_cases' t f g (maybe_enum_key_of_repr (dsum_enum t) tg)) h input pos_after_tag in destr (jump_dsum_cases_eq t f g) (jump_dsum_cases_if t f g) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_dsum_cases' t f f32 g32) tg input pos_after_tag #pop-options inline_for_extraction let read_dsum_cases' (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (leaf_reader (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (g32: leaf_reader g) (x: dsum_key t) : Tot (leaf_reader (parse_dsum_cases' t f g x)) = fun #rrel #rel input pos -> [@inline_let] let _ = synth_dsum_case_injective t x in match x with | Known x' -> read_synth' (dsnd (f x')) (synth_dsum_case t (Known x')) (f32 x') () input pos | Unknown x' -> read_synth' g (synth_dsum_case t (Unknown x')) g32 () input pos inline_for_extraction let read_dsum_cases_t (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (k: dsum_known_key t) : Tot Type = leaf_reader (parse_dsum_cases' t f g (Known k)) let read_dsum_cases_t_eq (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (k: dsum_known_key t) (x y : read_dsum_cases_t t f g k) : GTot Type0 = True inline_for_extraction let read_dsum_cases_t_if (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (k: dsum_known_key t) : Tot (if_combinator _ (read_dsum_cases_t_eq t f g k)) = fun cond (sv_true: cond_true cond -> Tot (read_dsum_cases_t t f g k)) (sv_false: cond_false cond -> Tot (read_dsum_cases_t t f g k)) #_ #_ input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let read_dsum_cases (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (leaf_reader (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (g32: leaf_reader g) (destr: dep_enum_destr _ (read_dsum_cases_t t f g)) (x: dsum_key t) : Tot (leaf_reader (parse_dsum_cases' t f g x)) = fun #_ #_ input pos -> match x with | Known k -> destr _ (read_dsum_cases_t_if t f g) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> read_dsum_cases' t f f32 g g32 (Known k)) k input pos | Unknown r -> read_dsum_cases' t f f32 g g32 (Unknown r) input pos #push-options "--z3rlimit 16" inline_for_extraction let read_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (p32: leaf_reader (parse_maybe_enum_key p (dsum_enum t))) (j: jumper p) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (leaf_reader (dsnd (f x)))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (g32: leaf_reader g) (destr: dep_enum_destr _ (read_dsum_cases_t t f g)) : Tot (leaf_reader (parse_dsum t p f g)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq_ t p f g (bytes_of_slice_from h input pos); valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_maybe_enum_key j (dsum_enum t) input pos in valid_facts (parse_dsum_cases' t f g k) h input pos' ; read_dsum_cases t f f32 g g32 destr k input pos' #pop-options inline_for_extraction let serialize32_dsum_type_of_tag (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (tg: dsum_key t) : Tot (serializer32 (serialize_dsum_type_of_tag t f sf g sg tg)) = match tg with | Known x' -> serialize32_ext (dsnd (f x')) (sf x') (sf32 x') (parse_dsum_type_of_tag t f g tg) () | Unknown x' -> serialize32_ext g sg sg32 (parse_dsum_type_of_tag t f g tg) () inline_for_extraction let serialize32_dsum_cases_aux (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (tg: dsum_key t) : Tot (serializer32 (serialize_dsum_cases t f sf g sg tg)) = [@inline_let] let _ = synth_dsum_case_injective t tg in [@inline_let] let _ = synth_dsum_case_inverse t tg in serialize32_synth (serialize32_dsum_type_of_tag t f sf sf32 sg32 tg) (synth_dsum_case t tg) (synth_dsum_case_recip t tg) (fun x -> synth_dsum_case_recip t tg x) () inline_for_extraction let serialize32_dsum_cases_t (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (sg: serializer g) (k: dsum_known_key t) : Tot Type = serializer32 (serialize_dsum_cases t f sf g sg (Known k)) let serialize32_dsum_cases_t_eq (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (sg: serializer g) (k: dsum_known_key t) (x y: serialize32_dsum_cases_t t f sf g sg k) : GTot Type0 = True inline_for_extraction let serialize32_dsum_cases_t_if (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (sg: serializer g) (k: dsum_known_key t) : Tot (if_combinator _ (serialize32_dsum_cases_t_eq t f sf g sg k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_dsum_cases_t t f sf g sg k))) (sv_false: (cond_false cond -> Tot (serialize32_dsum_cases_t t f sf g sg k))) x #rrel #rel output pos -> if cond then (sv_true () x output pos) else (sv_false () x output pos) inline_for_extraction let serialize32_dsum_cases (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (destr: dep_enum_destr _ (serialize32_dsum_cases_t t f sf g sg)) (tg: dsum_key t) : Tot (serializer32 (serialize_dsum_cases t f sf g sg tg)) = fun x #rrel #rel output pos -> match tg with | Known k -> destr _ (serialize32_dsum_cases_t_if t f sf g sg) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> serialize32_dsum_cases_aux t f sf sf32 sg32 (Known k)) k x output pos | Unknown r -> serialize32_dsum_cases_aux t f sf sf32 sg32 (Unknown r) x output pos inline_for_extraction let serialize32_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_maybe_enum_key _ s (dsum_enum t))) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (destr: dep_enum_destr _ (serialize32_dsum_cases_t t f sf g sg)) : Tot (serializer32 (serialize_dsum t s f sf g sg)) = fun x #_ #_ output pos -> [@inline_let] let _ = serialize_dsum_eq' t s f sf g sg x in let tg = dsum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_dsum_cases t f sf sf32 sg32 destr tg) tg x output pos let clens_dsum_tag (s: dsum) : Tot (clens (dsum_type s) (dsum_key s)) = { clens_cond = (fun _ -> True); clens_get = dsum_tag_of_data s; } let gaccessor_dsum_tag (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) : Tot (gaccessor (parse_dsum t p f g) (parse_maybe_enum_key p (dsum_enum t)) (clens_dsum_tag t)) = gaccessor_tagged_union_tag (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) inline_for_extraction let accessor_dsum_tag (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) : Tot (accessor (gaccessor_dsum_tag t p f g)) = accessor_tagged_union_tag (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) let clens_dsum_payload (s: dsum) (k: dsum_key s) : Tot (clens (dsum_type s) (dsum_type_of_tag s k)) = { clens_cond = (fun (x: dsum_type s) -> dsum_tag_of_data s x == k); clens_get = (fun (x: dsum_type s) -> synth_dsum_case_recip s k x <: Ghost (dsum_type_of_tag s k) (requires (dsum_tag_of_data s x == k)) (ensures (fun _ -> True))); } let clens_dsum_unknown_payload (s: dsum) : Tot (clens (dsum_type s) (dsum_type_of_unknown_tag s)) = { clens_cond = (fun (x: dsum_type s) -> Unknown? (dsum_tag_of_data s x)); clens_get = (fun (x: dsum_type s) -> synth_dsum_case_recip s (dsum_tag_of_data s x) x <: Ghost (dsum_type_of_unknown_tag s) (requires (Unknown? (dsum_tag_of_data s x))) (ensures (fun _ -> True))); } #push-options "--z3rlimit 16" let gaccessor_clens_dsum_payload' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) : Tot (gaccessor' (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k)) = fun (input: bytes) -> parse_dsum_eq3 t p f g input; let res = match parse p input with | Some (_, consumed) -> synth_dsum_case_inverse t k; synth_dsum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_dsum_case t k) (synth_dsum_case_recip t k) (); (consumed) | _ -> (0) // dummy in (res <: (res: _ { gaccessor_post' (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) input res } )) let gaccessor_clens_dsum_payload_injective (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ injective_precond (parse_dsum t p f g) sl sl' )) (ensures ( gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl' )) = parse_dsum_eq3 t p f g sl; parse_dsum_eq3 t p f g sl'; parse_injective (parse_dsum t p f g) sl sl' ; parse_injective p sl sl'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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" }
false
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser ku (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> k: LowParse.Spec.Sum.dsum_key t -> sl: LowParse.Bytes.bytes -> sl': LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (requires Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.Sum.parse_dsum_kind kt t f ku) == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\ LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Sum.parse_dsum t p f g) (LowParse.Spec.Sum.parse_dsum_type_of_tag' t f g k) (LowParse.Low.Sum.clens_dsum_payload t k) sl /\ LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Sum.parse_dsum t p f g) (LowParse.Spec.Sum.parse_dsum_type_of_tag' t f g k) (LowParse.Low.Sum.clens_dsum_payload t k) sl' /\ LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.Sum.parse_dsum t p f g) sl sl') (ensures LowParse.Low.Sum.gaccessor_clens_dsum_payload' t p f g k sl == LowParse.Low.Sum.gaccessor_clens_dsum_payload' t p f g k sl')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.dsum_key", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse_injective", "Prims.unit", "LowParse.Spec.Base.parse_strong_prefix", "LowParse.Spec.Sum.parse_dsum_kind", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.parse_dsum", "LowParse.Spec.Sum.parse_dsum_eq3", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Low.Base.Spec.gaccessor_pre", "LowParse.Spec.Sum.parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Sum.parse_dsum_type_of_tag'", "LowParse.Low.Sum.clens_dsum_payload", "LowParse.Spec.Base.no_lookahead_on_precond", "Prims.squash", "Prims.nat", "LowParse.Low.Sum.gaccessor_clens_dsum_payload'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let gaccessor_clens_dsum_payload_no_lookahead (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl': bytes) : Lemma (requires ((parse_dsum_kind kt t f ku).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ no_lookahead_on_precond (parse_dsum t p f g) sl sl')) (ensures (gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl')) =
parse_dsum_eq3 t p f g sl; parse_dsum_eq3 t p f g sl'; parse_strong_prefix (parse_dsum t p f g) sl sl'; parse_injective p sl sl'
false
LocalState.fst
LocalState.t1
val t1: unit -> Tac unit
val t1: unit -> Tac unit
let t1 (_:unit) : Tac unit = let r1 = alloc {x = 1; y = 1} in let r2 = alloc #st2 (fun x -> x + 1) in let s1 = read r1 in let s2 = read r2 in let s = s1.x + s1.y + s2 1 in if s <> 4 then fail "Expected 4" else let _ = write r1 ({x = 2; y = 2}) in let _ = write r2 (fun x -> x + 2) in let s1 = read r1 in let s2 = read r2 in let s = s1.x + s1.y + s2 1 in if s <> 7 then fail "Expected 7" else try let _ = write r1 ({x=3; y=3}) in t2 () with | _ -> let s1 = read r1 in let s = s1.x + s1.y in if s <> 6 then fail "Expected 6" else ()
{ "file_name": "examples/tactics/LocalState.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 50, "start_col": 0, "start_line": 29 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LocalState open FStar.Tactics.V2 type st1 = { x : int; y : int; } type st2 = int -> int let t2 () : Tac unit = fail "always fail"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LocalState.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.op_disEquality", "Prims.int", "FStar.Tactics.V2.Derived.fail", "Prims.bool", "FStar.Tactics.V2.Derived.try_with", "LocalState.t2", "FStar.Stubs.Tactics.V2.Builtins.write", "LocalState.st1", "LocalState.Mkst1", "Prims.exn", "Prims.op_Addition", "LocalState.__proj__Mkst1__item__x", "LocalState.__proj__Mkst1__item__y", "FStar.Stubs.Tactics.V2.Builtins.read", "LocalState.st2", "FStar.Stubs.Tactics.Types.tref", "FStar.Stubs.Tactics.V2.Builtins.alloc" ]
[]
false
true
false
false
false
let t1 (_: unit) : Tac unit =
let r1 = alloc ({ x = 1; y = 1 }) in let r2 = alloc #st2 (fun x -> x + 1) in let s1 = read r1 in let s2 = read r2 in let s = s1.x + s1.y + s2 1 in if s <> 4 then fail "Expected 4" else let _ = write r1 ({ x = 2; y = 2 }) in let _ = write r2 (fun x -> x + 2) in let s1 = read r1 in let s2 = read r2 in let s = s1.x + s1.y + s2 1 in if s <> 7 then fail "Expected 7" else try let _ = write r1 ({ x = 3; y = 3 }) in t2 () with | _ -> let s1 = read r1 in let s = s1.x + s1.y in if s <> 6 then fail "Expected 6"
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_3
val jump_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val jump_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 291, "start_col": 0, "start_line": 289 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.jump_bounded_int32'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let jump_bounded_int32_3 min32 max32 =
jump_bounded_int32' min32 max32 3
false
Steel.HigherReference.fst
Steel.HigherReference.share_gen
val share_gen (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit u (pts_to r p x) (fun _ -> pts_to r p1 x `star` pts_to r p2 x) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True)
val share_gen (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit u (pts_to r p x) (fun _ -> pts_to r p1 x `star` pts_to r p2 x) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True)
let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 264, "start_col": 0, "start_line": 249 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ref a -> p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.HigherReference.ref", "Steel.HigherReference.intro_pts_to", "Prims.unit", "Steel.HigherReference.share_atomic_raw_gen", "Steel.Effect.Atomic.elim_pure", "Steel.HigherReference.perm_ok", "Steel.Effect.Atomic.rewrite_slprop", "Steel.HigherReference.pts_to", "FStar.Ghost.reveal", "Steel.HigherReference.pts_to'", "Steel.Memory.mem", "Steel.PCMFrac.fractional", "FStar.Ghost.hide", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Steel.Effect.Common.star", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.eq2", "Steel.FractionalPermission.sum_perm", "Prims.l_True" ]
[]
false
true
false
false
false
let share_gen (#a: Type) (#uses: _) (#p: perm) (#v: erased a) (r: ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> (pts_to r p1 v) `star` (pts_to r p2 v)) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) =
let v_old:erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_u16_le
val read_u16_le : leaf_reader parse_u16_le
val read_u16_le : leaf_reader parse_u16_le
let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 349, "start_col": 0, "start_line": 343 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_reader LowParse.Spec.BoundedInt.parse_u16_le
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.read_inline_synth'", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "FStar.UInt16.t", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.synth_u16_le", "LowParse.Low.BoundedInt.read_bounded_integer_le_2", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "LowParse.Spec.BoundedInt.synth_u16_le_injective" ]
[]
false
false
false
true
false
let read_u16_le =
[@@ inline_let ]let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 ()
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_4
val jump_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val jump_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 295, "start_col": 0, "start_line": 293 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.jump_bounded_int32'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32" ]
[]
false
false
false
false
false
let jump_bounded_int32_4 min32 max32 =
jump_bounded_int32' min32 max32 4
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_le_2
val read_bounded_integer_le_2 : leaf_reader (parse_bounded_integer_le 2)
val read_bounded_integer_le_2 : leaf_reader (parse_bounded_integer_le 2)
let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 315, "start_col": 0, "start_line": 308 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer_le 2)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.bounded_integer_of_le", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.Int.Cast.uint16_to_uint32", "Prims.unit", "FStar.Endianness.lemma_le_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "LowStar.Endianness.u16", "LowStar.Endianness.load16_le_i", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.bounded_integer_of_le_injective" ]
[]
false
false
false
false
false
let read_bounded_integer_le_2 =
[@@ inline_let ]let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_le_1
val read_bounded_integer_le_1 : leaf_reader (parse_bounded_integer_le 1)
val read_bounded_integer_le_1 : leaf_reader (parse_bounded_integer_le 1)
let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 306, "start_col": 0, "start_line": 298 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer_le 1)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.bounded_integer_of_le", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.Int.Cast.uint8_to_uint32", "LowStar.Monotonic.Buffer.index", "Prims.unit", "FStar.Endianness.lemma_le_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "LowParse.Endianness.index_le_to_n", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.bounded_integer_of_le_injective" ]
[]
false
false
false
false
false
let read_bounded_integer_le_1 =
[@@ inline_let ]let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_le_4
val read_bounded_integer_le_4 : leaf_reader (parse_bounded_integer_le 4)
val read_bounded_integer_le_4 : leaf_reader (parse_bounded_integer_le 4)
let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 341, "start_col": 0, "start_line": 335 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer_le 4)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.bounded_integer_of_le", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "LowStar.Endianness.load32_le_i", "LowStar.Endianness.u32", "Prims.unit", "FStar.Endianness.lemma_le_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.bounded_integer_of_le_injective" ]
[]
false
false
false
false
false
let read_bounded_integer_le_4 =
[@@ inline_let ]let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i b pos)
false
Lattice.fst
Lattice.abides
val abides (#a: _) (f: repr0 a) (ann: annot) : prop
val abides (#a: _) (f: repr0 a) (ann: annot) : prop
let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0))))
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 32, "start_col": 0, "start_line": 29 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Lattice.repr0 a -> ann: Lattice.annot -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Lattice.repr0", "Lattice.annot", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "Lattice.RD", "Prims.l_Forall", "Lattice.state", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.fst", "Lattice.WR", "FStar.Pervasives.Native.snd", "Lattice.EXN", "FStar.Pervasives.Native.uu___is_Some", "Prims.prop" ]
[]
false
false
false
true
true
let abides #a (f: repr0 a) (ann: annot) : prop =
(ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0))))
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.valid_dsum_intro_known
val valid_dsum_intro_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ (let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ (let Known k = k' in valid (dsnd (f k)) h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos))))) (ensures (let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload)))
val valid_dsum_intro_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ (let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ (let Known k = k' in valid (dsnd (f k)) h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos))))) (ensures (let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload)))
let valid_dsum_intro_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ ( let Known k = k' in valid (dsnd (f k)) h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos) )))) (ensures ( let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload) )) = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts (dsnd (f k)) h input pos_payload; valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos)
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 57, "end_line": 1131, "start_col": 0, "start_line": 1099 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; } let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) inline_for_extraction let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) = accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) let clens_sum_payload (s: sum) (k: sum_key s) : Tot (clens (sum_type s) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_type s) -> sum_tag_of_data s x == k); clens_get = (fun (x: sum_type s) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (sum_tag_of_data s x == k)) (ensures (fun _ -> True))); } #push-options "--z3rlimit 32" let gaccessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = fun (input: bytes) -> parse_sum_eq'' t p pc input; let res = match parse p input with | Some (_, consumed) -> synth_sum_case_inverse t k; synth_sum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); (consumed) | _ -> 0 // dummy in (res <: (res: _ { gaccessor_post' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) input res } )) #push-options "--z3rlimit 64" let gaccessor_clens_sum_payload_injective (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ injective_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_injective (parse_sum t p pc) sl sl' ; parse_injective p sl sl' #pop-options let gaccessor_clens_sum_payload_no_lookahead (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( (parse_sum_kind kt t pc).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ no_lookahead_on_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_strong_prefix (parse_sum t p pc) sl sl' ; parse_injective p sl sl' let gaccessor_clens_sum_payload (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_injective t p pc k x)); Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_no_lookahead t p pc k x)); gaccessor_prop_equiv (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) (gaccessor_clens_sum_payload' t p pc k); gaccessor_clens_sum_payload' t p pc k inline_for_extraction let accessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_sum t p pc) h input pos /\ (clens_sum_payload t k).clens_cond (contents (parse_sum t p pc) h input pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h (gaccessor_clens_sum_payload t p pc k) input pos )) = let h = HST.get () in [@inline_let] let _ = let pos' = get_valid_pos (parse_sum t p pc) h input pos in let large = bytes_of_slice_from h input pos in slice_access_eq h (gaccessor_clens_sum_payload t p pc k) input pos; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq'' t p pc large; valid_facts p h input pos in j input pos #pop-options inline_for_extraction let accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k)) = fun #rrel #rel -> accessor_clens_sum_payload' t j pc k #rrel #rel let clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_cases s k) -> True); clens_get = (fun (x: sum_cases s k) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (True)) (ensures (fun _ -> True))); } let gaccessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum_cases' t pc k) (dsnd (pc k)) (clens_sum_cases_payload t k)) = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); gaccessor_ext (gaccessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let accessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_cases_payload t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) () in accessor_ext (accessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let validate_dsum_cases_t (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot Type = validator (parse_dsum_cases' s f g x) let validate_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2 : validate_dsum_cases_t s f g x) : GTot Type0 = True inline_for_extraction let validate_dsum_cases_if' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (cond: bool) (ift: (cond_true cond -> Tot (validate_dsum_cases_t s f g x))) (iff: (cond_false cond -> Tot (validate_dsum_cases_t s f g x))) : Tot (validate_dsum_cases_t s f g x) = fun #rrel #rel input len -> if cond then (ift () <: validate_dsum_cases_t s f g x) input len else (iff () <: validate_dsum_cases_t s f g x) input len inline_for_extraction let validate_dsum_cases_if (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot (if_combinator _ (validate_dsum_cases_eq s f g x)) = validate_dsum_cases_if' s f g x inline_for_extraction let validate_dsum_cases' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (x: dsum_key s) : Tot (validate_dsum_cases_t s f g x) = [@inline_let] let _ = synth_dsum_case_injective s x in match x with | Known x' -> validate_synth (f' x') (synth_dsum_case s (Known x')) () <: validator (parse_dsum_cases' s f g x) | Unknown x' -> validate_synth g' (synth_dsum_case s (Unknown x')) () <: validator (parse_dsum_cases' s f g x) inline_for_extraction let validate_dsum_cases'_destr (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (destr: dep_enum_destr _ (fun k -> validate_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (validate_dsum_cases_t s f g x) = fun #rrel #rel input pos -> match x with | Known k -> destr _ (fun k -> validate_dsum_cases_if s f g (Known k)) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> validate_dsum_cases' s f f' g' (Known k)) k input pos | Unknown r -> validate_dsum_cases' s f f' g' (Unknown r) input pos inline_for_extraction let validate_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (destr: dep_enum_destr _ (fun k -> validate_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (validator (parse_dsum_cases s f g x)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_dsum_cases' s f g x) h input (uint64_to_uint32 pos); valid_facts (parse_dsum_cases s f g x) h input (uint64_to_uint32 pos); parse_dsum_cases_eq' s f g x (bytes_of_slice_from h input (uint64_to_uint32 pos)) in validate_dsum_cases'_destr s f f' g' destr x input pos #push-options "--z3rlimit 40" inline_for_extraction let validate_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (v: validator p) (p32: leaf_reader p) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (validator (dsnd (f x)))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (g32: validator g) (destr: dep_maybe_enum_destr_t (dsum_enum t) (validate_dsum_cases_t t f g)) : Tot (validator (parse_dsum t p f g)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_dsum_eq' t p f g (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_dsum t p f g) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let pos_after_tag = v input pos in if is_error pos_after_tag then pos_after_tag else let tg = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts (parse_dsum_cases' t f g (maybe_enum_key_of_repr (dsum_enum t) tg)) h input (uint64_to_uint32 pos_after_tag) in destr (validate_dsum_cases_eq t f g) (validate_dsum_cases_if t f g) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_dsum_cases' t f f32 g32) tg input pos_after_tag #pop-options #reset-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 8, "max_fuel": 2, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser ku (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Enum.parse_maybe_enum_key p (LowParse.Spec.Sum.dsum_enum t)) h input pos /\ (let k' = LowParse.Low.Base.Spec.contents (LowParse.Spec.Enum.parse_maybe_enum_key p (LowParse.Spec.Sum.dsum_enum t)) h input pos in Known? k' /\ (let _ = k' in (let LowParse.Spec.Enum.Known #_ #_ #_ k = _ in LowParse.Low.Base.Spec.valid (FStar.Pervasives.dsnd (f k)) h input (LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.Enum.parse_maybe_enum_key p (LowParse.Spec.Sum.dsum_enum t)) h input pos)) <: Prims.logical))) (ensures (let _ = LowParse.Low.Base.Spec.contents (LowParse.Spec.Enum.parse_maybe_enum_key p (LowParse.Spec.Sum.dsum_enum t)) h input pos in (let LowParse.Spec.Enum.Known #_ #_ #_ k = _ in let pos_payload = LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.Enum.parse_maybe_enum_key p (LowParse.Spec.Sum.dsum_enum t)) h input pos in LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Sum.parse_dsum t p f g) h input pos (LowParse.Spec.Sum.synth_dsum_case t (LowParse.Spec.Enum.Known k) (LowParse.Low.Base.Spec.contents (FStar.Pervasives.dsnd (f k)) h input pos_payload )) (LowParse.Low.Base.Spec.get_valid_pos (FStar.Pervasives.dsnd (f k)) h input pos_payload)) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Sum.parse_dsum_eq", "LowParse.Slice.bytes_of_slice_from", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Sum.parse_dsum_kind", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.parse_dsum", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Low.Base.Spec.contents", "Prims.l_and", "LowParse.Low.Base.Spec.valid", "Prims.b2t", "LowParse.Spec.Enum.uu___is_Known", "Prims.logical", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Sum.synth_dsum_case", "LowParse.Spec.Enum.Known", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let valid_dsum_intro_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ (let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ (let Known k = k' in valid (dsnd (f k)) h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos))))) (ensures (let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload))) =
valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts (dsnd (f k)) h input pos_payload; valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_u32_le
val read_u32_le : leaf_reader parse_u32_le
val read_u32_le : leaf_reader parse_u32_le
let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 356, "start_col": 0, "start_line": 351 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_reader LowParse.Spec.BoundedInt.parse_u32_le
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.read_inline_synth'", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "FStar.UInt32.t", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.synth_u32_le", "LowParse.Low.BoundedInt.read_bounded_integer_le_4" ]
[]
false
false
false
true
false
let read_u32_le =
read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 ()
false
Lattice.fst
Lattice.ann_le
val ann_le (ann1 ann2: annot) : prop
val ann_le (ann1 ann2: annot) : prop
let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 76, "start_col": 0, "start_line": 75 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ann1: Lattice.annot -> ann2: Lattice.annot -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Lattice.annot", "Prims.l_Forall", "Lattice.eff_label", "Prims.l_imp", "Prims.b2t", "Prims.prop" ]
[]
false
false
false
true
true
let ann_le (ann1 ann2: annot) : prop =
forall x. ann1 x ==> ann2 x
false
Lattice.fst
Lattice.ite
val ite : p: Type0 -> q: Type0 -> r: Type0 -> Prims.logical
let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r)
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 102, "start_col": 0, "start_line": 102 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0) let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = let r = fun s0 -> match c s0 with | Some x, s1 -> f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Type0 -> q: Type0 -> r: Type0 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_and", "Prims.l_imp", "Prims.l_not", "Prims.logical" ]
[]
false
false
false
true
true
let ite (p q r: Type0) =
(p ==> q) /\ (~p ==> r)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_integer_le_3
val read_bounded_integer_le_3 : leaf_reader (parse_bounded_integer_le 3)
val read_bounded_integer_le_3 : leaf_reader (parse_bounded_integer_le 3)
let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) )
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 331, "start_col": 0, "start_line": 319 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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" }
false
LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_integer_le 3)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.make_total_constant_size_reader", "FStar.UInt32.__uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.bounded_integer_of_le", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.UInt32.add", "FStar.Int.Cast.uint8_to_uint32", "LowParse.Low.BoundedInt.mul256", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.pow2", "FStar.Endianness.lemma_le_to_n_is_bounded", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v", "Prims.op_Addition", "LowStar.Endianness.u16", "LowStar.Endianness.load16_le_i", "LowStar.Monotonic.Buffer.index", "FStar.Endianness.reveal_le_to_n", "FStar.Seq.Properties.lemma_split", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.BoundedInt.bounded_integer_of_le_injective" ]
[]
false
false
false
false
false
let read_bounded_integer_le_3 =
[@@ inline_let ]let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); (Cast.uint8_to_uint32 lo) `U32.add` (mul256 hi))
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_integer_le_1
val write_bounded_integer_le_1 : leaf_writer_strong (serialize_bounded_integer_le 1)
val write_bounded_integer_le_1 : leaf_writer_strong (serialize_bounded_integer_le 1)
let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 72, "end_line": 366, "start_col": 0, "start_line": 365 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_integer_le 1)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "LowParse.Low.BoundedInt.serialize32_bounded_integer_le_1" ]
[]
false
false
false
false
false
let write_bounded_integer_le_1 =
leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 ()
false
Steel.HigherReference.fst
Steel.HigherReference.gather
val gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) : SteelGhost unit uses (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r (sum_perm p0 p1) v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1)
val gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) : SteelGhost unit uses (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r (sum_perm p0 p1) v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1)
let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 305, "start_col": 0, "start_line": 291 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.HigherReference.ref", "Steel.HigherReference.intro_pts_to", "Steel.FractionalPermission.sum_perm", "Prims.unit", "Prims.l_and", "Prims.eq2", "Steel.HigherReference.perm_ok", "Steel.HigherReference.gather_atomic_raw", "Steel.Effect.Atomic.elim_pure", "Steel.Effect.Atomic.rewrite_slprop", "Steel.HigherReference.pts_to", "FStar.Ghost.reveal", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to_raw", "Steel.Effect.Common.pure", "Steel.Memory.mem", "Steel.PCMFrac.fractional", "FStar.Ghost.hide", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
true
false
false
false
let gather (#a: Type) (#uses: _) (#p0 #p1: perm) (#v0 #v1: erased a) (r: ref a) =
let v0_old:erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old:erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) ((pts_to_raw r p0 v0) `star` (pure (perm_ok p0))) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) ((pts_to_raw r p1 v1) `star` (pure (perm_ok p1))) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r
false
Lattice.fst
Lattice.coerce
val coerce (#a #b: _) (x: a{a == b}) : b
val coerce (#a #b: _) (x: a{a == b}) : b
let coerce #a #b (x:a{a == b}) : b = x
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 7, "start_col": 0, "start_line": 7 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a{a == b} -> b
Prims.Tot
[ "total" ]
[]
[ "Prims.eq2" ]
[]
false
false
false
false
false
let coerce #a #b (x: a{a == b}) : b =
x
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_integer_le_3
val write_bounded_integer_le_3 : leaf_writer_strong (serialize_bounded_integer_le 3)
val write_bounded_integer_le_3 : leaf_writer_strong (serialize_bounded_integer_le 3)
let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 103, "end_line": 407, "start_col": 0, "start_line": 407 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_integer_le 3)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "LowParse.Low.BoundedInt.serialize32_bounded_integer_le_3" ]
[]
false
false
false
false
false
let write_bounded_integer_le_3 =
leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 ()
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_integer_le_4
val write_bounded_integer_le_4 : leaf_writer_strong (serialize_bounded_integer_le 4)
val write_bounded_integer_le_4 : leaf_writer_strong (serialize_bounded_integer_le 4)
let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 103, "end_line": 419, "start_col": 0, "start_line": 419 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_integer_le 4)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "LowParse.Low.BoundedInt.serialize32_bounded_integer_le_4" ]
[]
false
false
false
false
false
let write_bounded_integer_le_4 =
leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 ()
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_u16_le
val write_u16_le : leaf_writer_strong serialize_u16_le
val write_u16_le : leaf_writer_strong serialize_u16_le
let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 107, "end_line": 423, "start_col": 0, "start_line": 421 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_writer_strong LowParse.Spec.BoundedInt.serialize_u16_le
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.write_synth", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "LowParse.Low.BoundedInt.write_bounded_integer_le_2", "FStar.UInt16.t", "LowParse.Spec.BoundedInt.synth_u16_le", "LowParse.Spec.BoundedInt.synth_u16_le_recip", "Prims.eq2", "Prims.squash", "LowParse.Spec.Combinators.synth_inverse", "LowParse.Spec.BoundedInt.synth_u16_le_inverse", "Prims.unit", "LowParse.Spec.BoundedInt.synth_u16_le_injective" ]
[]
false
false
false
true
false
let write_u16_le =
[@@ inline_let ]let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) ()
false
Lattice.fst
Lattice.sublist
val sublist : l1: Prims.list Lattice.eff_label -> l2: Prims.list Lattice.eff_label -> Prims.logical
let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 45, "start_col": 0, "start_line": 44 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Prims.list Lattice.eff_label -> l2: Prims.list Lattice.eff_label -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Lattice.eff_label", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "FStar.List.Tot.Base.mem", "Prims.logical" ]
[]
false
false
false
true
true
let sublist (l1 l2: list eff_label) =
forall x. mem x l1 ==> mem x l2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.serialize32_bounded_integer_le_1
val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1)
val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1)
let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 363, "start_col": 0, "start_line": 358 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_integer_le 1)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.BoundedInt.bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "Prims.unit", "LowParse.Low.Base.mbuffer_upd", "FStar.Ghost.hide", "Prims.nat", "FStar.UInt32.v", "Prims.op_Addition", "FStar.Int.Cast.uint32_to_uint8", "LowParse.Endianness.index_n_to_le", "LowParse.Spec.BoundedInt.bounded_integer_prop_equiv" ]
[]
false
false
false
false
false
let serialize32_bounded_integer_le_1 =
fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.gaccessor_clens_dsum_payload_injective
val gaccessor_clens_dsum_payload_injective (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl': bytes) : Lemma (requires (gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ injective_precond (parse_dsum t p f g) sl sl')) (ensures (gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl'))
val gaccessor_clens_dsum_payload_injective (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl': bytes) : Lemma (requires (gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ injective_precond (parse_dsum t p f g) sl sl')) (ensures (gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl'))
let gaccessor_clens_dsum_payload_injective (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ injective_precond (parse_dsum t p f g) sl sl' )) (ensures ( gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl' )) = parse_dsum_eq3 t p f g sl; parse_dsum_eq3 t p f g sl'; parse_injective (parse_dsum t p f g) sl sl' ; parse_injective p sl sl'
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 26, "end_line": 1863, "start_col": 0, "start_line": 1841 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; } let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) inline_for_extraction let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) = accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) let clens_sum_payload (s: sum) (k: sum_key s) : Tot (clens (sum_type s) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_type s) -> sum_tag_of_data s x == k); clens_get = (fun (x: sum_type s) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (sum_tag_of_data s x == k)) (ensures (fun _ -> True))); } #push-options "--z3rlimit 32" let gaccessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = fun (input: bytes) -> parse_sum_eq'' t p pc input; let res = match parse p input with | Some (_, consumed) -> synth_sum_case_inverse t k; synth_sum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); (consumed) | _ -> 0 // dummy in (res <: (res: _ { gaccessor_post' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) input res } )) #push-options "--z3rlimit 64" let gaccessor_clens_sum_payload_injective (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ injective_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_injective (parse_sum t p pc) sl sl' ; parse_injective p sl sl' #pop-options let gaccessor_clens_sum_payload_no_lookahead (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( (parse_sum_kind kt t pc).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ no_lookahead_on_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_strong_prefix (parse_sum t p pc) sl sl' ; parse_injective p sl sl' let gaccessor_clens_sum_payload (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_injective t p pc k x)); Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_no_lookahead t p pc k x)); gaccessor_prop_equiv (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) (gaccessor_clens_sum_payload' t p pc k); gaccessor_clens_sum_payload' t p pc k inline_for_extraction let accessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_sum t p pc) h input pos /\ (clens_sum_payload t k).clens_cond (contents (parse_sum t p pc) h input pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h (gaccessor_clens_sum_payload t p pc k) input pos )) = let h = HST.get () in [@inline_let] let _ = let pos' = get_valid_pos (parse_sum t p pc) h input pos in let large = bytes_of_slice_from h input pos in slice_access_eq h (gaccessor_clens_sum_payload t p pc k) input pos; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq'' t p pc large; valid_facts p h input pos in j input pos #pop-options inline_for_extraction let accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k)) = fun #rrel #rel -> accessor_clens_sum_payload' t j pc k #rrel #rel let clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_cases s k) -> True); clens_get = (fun (x: sum_cases s k) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (True)) (ensures (fun _ -> True))); } let gaccessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum_cases' t pc k) (dsnd (pc k)) (clens_sum_cases_payload t k)) = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); gaccessor_ext (gaccessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let accessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_cases_payload t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) () in accessor_ext (accessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let validate_dsum_cases_t (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot Type = validator (parse_dsum_cases' s f g x) let validate_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2 : validate_dsum_cases_t s f g x) : GTot Type0 = True inline_for_extraction let validate_dsum_cases_if' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (cond: bool) (ift: (cond_true cond -> Tot (validate_dsum_cases_t s f g x))) (iff: (cond_false cond -> Tot (validate_dsum_cases_t s f g x))) : Tot (validate_dsum_cases_t s f g x) = fun #rrel #rel input len -> if cond then (ift () <: validate_dsum_cases_t s f g x) input len else (iff () <: validate_dsum_cases_t s f g x) input len inline_for_extraction let validate_dsum_cases_if (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot (if_combinator _ (validate_dsum_cases_eq s f g x)) = validate_dsum_cases_if' s f g x inline_for_extraction let validate_dsum_cases' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (x: dsum_key s) : Tot (validate_dsum_cases_t s f g x) = [@inline_let] let _ = synth_dsum_case_injective s x in match x with | Known x' -> validate_synth (f' x') (synth_dsum_case s (Known x')) () <: validator (parse_dsum_cases' s f g x) | Unknown x' -> validate_synth g' (synth_dsum_case s (Unknown x')) () <: validator (parse_dsum_cases' s f g x) inline_for_extraction let validate_dsum_cases'_destr (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (destr: dep_enum_destr _ (fun k -> validate_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (validate_dsum_cases_t s f g x) = fun #rrel #rel input pos -> match x with | Known k -> destr _ (fun k -> validate_dsum_cases_if s f g (Known k)) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> validate_dsum_cases' s f f' g' (Known k)) k input pos | Unknown r -> validate_dsum_cases' s f f' g' (Unknown r) input pos inline_for_extraction let validate_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (validator (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : validator g) (destr: dep_enum_destr _ (fun k -> validate_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (validator (parse_dsum_cases s f g x)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_dsum_cases' s f g x) h input (uint64_to_uint32 pos); valid_facts (parse_dsum_cases s f g x) h input (uint64_to_uint32 pos); parse_dsum_cases_eq' s f g x (bytes_of_slice_from h input (uint64_to_uint32 pos)) in validate_dsum_cases'_destr s f f' g' destr x input pos #push-options "--z3rlimit 40" inline_for_extraction let validate_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (v: validator p) (p32: leaf_reader p) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (validator (dsnd (f x)))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (g32: validator g) (destr: dep_maybe_enum_destr_t (dsum_enum t) (validate_dsum_cases_t t f g)) : Tot (validator (parse_dsum t p f g)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_dsum_eq' t p f g (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_dsum t p f g) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let pos_after_tag = v input pos in if is_error pos_after_tag then pos_after_tag else let tg = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts (parse_dsum_cases' t f g (maybe_enum_key_of_repr (dsum_enum t) tg)) h input (uint64_to_uint32 pos_after_tag) in destr (validate_dsum_cases_eq t f g) (validate_dsum_cases_if t f g) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_dsum_cases' t f f32 g32) tg input pos_after_tag #pop-options #reset-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" let valid_dsum_intro_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ ( let Known k = k' in valid (dsnd (f k)) h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos) )))) (ensures ( let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload) )) = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts (dsnd (f k)) h input pos_payload; valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos) let valid_dsum_intro_unknown (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in Unknown? k' /\ valid g h input (get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos) ))) (ensures ( let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Unknown r) (contents g h input pos_payload)) (get_valid_pos g h input pos_payload) )) = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts g h input pos_payload; valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos) #reset-options inline_for_extraction let finalize_dsum_case_known (t: dsum) (#kt: parser_kind) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (destr: enum_repr_of_key'_t (dsum_enum t)) (k: dsum_known_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (dsum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (f k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (dsum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_dsum t p f g) h' input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload) )) = let pos1 = write_enum_key w (dsum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_facts (parse_enum_key p (dsum_enum t)) h input pos; valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let sq = bytes_of_slice_from h input pos in parse_enum_key_eq p (dsum_enum t) sq; parse_maybe_enum_key_eq p (dsum_enum t) sq; valid_dsum_intro_known h t p f g input pos in () inline_for_extraction let finalize_dsum_case_unknown (t: dsum) (#kt: parser_kind) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (r: unknown_enum_repr (dsum_enum t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length s r in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid g h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length s r in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_dsum t p f g) h' input pos (synth_dsum_case t (Unknown r) (contents g h input pos_payload)) (get_valid_pos g h input pos_payload) )) = let pos1 = w r input pos in let h = HST.get () in [@inline_let] let _ = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; valid_facts p h input pos; let sq = bytes_of_slice_from h input pos in parse_maybe_enum_key_eq p (dsum_enum t) sq; valid_dsum_intro_unknown h t p f g input pos in () let valid_dsum_elim_tag (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_dsum t p f g) h input pos )) (ensures ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ contents (parse_maybe_enum_key p (dsum_enum t)) h input pos == dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos) )) = let _ = parse_dsum_eq_ t p f g (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_dsum t p f g) h input pos in let _ = valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos in () inline_for_extraction let read_dsum_tag (t: dsum) (#kt: parser_kind) (#p: parser kt (dsum_repr_type t)) (p32: leaf_reader p) (destr: maybe_enum_destr_t (maybe_enum_key (dsum_enum t)) (dsum_enum t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (dsum_key t) (requires (fun h -> valid (parse_dsum t p f g) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_dsum_elim_tag h t p f g input pos in read_maybe_enum_key p32 (dsum_enum t) destr input pos #push-options "--z3rlimit 32" let valid_dsum_elim_known (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_dsum t p f g) h input pos /\ Known? (dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos)) )) (ensures ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in Known? k' /\ ( let Known k = k' in valid (dsnd (f k)) h input pos_payload /\ valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Known k) (contents (dsnd (f k)) h input pos_payload)) (get_valid_pos (dsnd (f k)) h input pos_payload) )))) = valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos); valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Known k = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts (dsnd (f k)) h input pos_payload #pop-options let valid_dsum_elim_unknown (h: HS.mem) (t: dsum) (#kt: parser_kind) (p: parser kt (dsum_repr_type t)) (f: ((x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_dsum t p f g) h input pos /\ Unknown? (dsum_tag_of_data t (contents (parse_dsum t p f g) h input pos)) )) (ensures ( valid (parse_maybe_enum_key p (dsum_enum t)) h input pos /\ ( let k' = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in Unknown? k' /\ ( let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid g h input pos_payload /\ valid_content_pos (parse_dsum t p f g) h input pos (synth_dsum_case t (Unknown r) (contents g h input pos_payload)) (get_valid_pos g h input pos_payload) )))) = valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq t p f g (bytes_of_slice_from h input pos); valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let Unknown r = contents (parse_maybe_enum_key p (dsum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_maybe_enum_key p (dsum_enum t)) h input pos in valid_facts g h input pos_payload inline_for_extraction let jump_dsum_cases_t (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot Type = jumper (parse_dsum_cases' s f g x) let jump_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2 : jump_dsum_cases_t s f g x) : GTot Type0 = True inline_for_extraction let jump_dsum_cases_if' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (cond: bool) (ift: (cond_true cond -> Tot (jump_dsum_cases_t s f g x))) (iff: (cond_false cond -> Tot (jump_dsum_cases_t s f g x))) : Tot (jump_dsum_cases_t s f g x) = fun #rrel #rel input len -> if cond then (ift () <: jump_dsum_cases_t s f g x) input len else (iff () <: jump_dsum_cases_t s f g x) input len inline_for_extraction let jump_dsum_cases_if (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot (if_combinator _ (jump_dsum_cases_eq s f g x)) = jump_dsum_cases_if' s f g x inline_for_extraction let jump_dsum_cases' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (jumper (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : jumper g) (x: dsum_key s) : Tot (jump_dsum_cases_t s f g x) = synth_dsum_case_injective s x; match x with | Known x' -> jump_synth (f' x') (synth_dsum_case s (Known x')) () <: jumper (parse_dsum_cases' s f g x) | Unknown x' -> jump_synth g' (synth_dsum_case s (Unknown x')) () <: jumper (parse_dsum_cases' s f g x) inline_for_extraction let jump_dsum_cases'_destr (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (jumper (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : jumper g) (destr: dep_enum_destr _ (fun k -> jump_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (jump_dsum_cases_t s f g x) = fun #rrel #rel input pos -> match x with | Known k -> destr _ (fun k -> jump_dsum_cases_if s f g (Known k)) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> jump_dsum_cases' s f f' g' (Known k)) k input pos | Unknown r -> jump_dsum_cases' s f f' g' (Unknown r) input pos inline_for_extraction let jump_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (f' : (x: dsum_known_key s) -> Tot (jumper (dsnd (f x)))) (#k: parser_kind) (#g: parser k (dsum_type_of_unknown_tag s)) (g' : jumper g) (destr: dep_enum_destr _ (fun k -> jump_dsum_cases_t s f g (Known k))) (x: dsum_key s) : Tot (jumper (parse_dsum_cases s f g x)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_dsum_cases' s f g x) h input pos; valid_facts (parse_dsum_cases s f g x) h input pos; parse_dsum_cases_eq' s f g x (bytes_of_slice_from h input pos) in jump_dsum_cases'_destr s f f' g' destr x input pos #push-options "--z3rlimit 16" inline_for_extraction let jump_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (jumper (dsnd (f x)))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (g32: jumper g) (destr: dep_maybe_enum_destr_t (dsum_enum t) (jump_dsum_cases_t t f g)) : Tot (jumper (parse_dsum t p f g)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_dsum_eq' t p f g (bytes_of_slice_from h input pos) in [@inline_let] let _ = valid_facts (parse_dsum t p f g) h input pos in [@inline_let] let _ = valid_facts p h input pos in let pos_after_tag = v input pos in let tg = p32 input pos in [@inline_let] let _ = valid_facts (parse_dsum_cases' t f g (maybe_enum_key_of_repr (dsum_enum t) tg)) h input pos_after_tag in destr (jump_dsum_cases_eq t f g) (jump_dsum_cases_if t f g) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_dsum_cases' t f f32 g32) tg input pos_after_tag #pop-options inline_for_extraction let read_dsum_cases' (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (leaf_reader (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (g32: leaf_reader g) (x: dsum_key t) : Tot (leaf_reader (parse_dsum_cases' t f g x)) = fun #rrel #rel input pos -> [@inline_let] let _ = synth_dsum_case_injective t x in match x with | Known x' -> read_synth' (dsnd (f x')) (synth_dsum_case t (Known x')) (f32 x') () input pos | Unknown x' -> read_synth' g (synth_dsum_case t (Unknown x')) g32 () input pos inline_for_extraction let read_dsum_cases_t (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (k: dsum_known_key t) : Tot Type = leaf_reader (parse_dsum_cases' t f g (Known k)) let read_dsum_cases_t_eq (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (k: dsum_known_key t) (x y : read_dsum_cases_t t f g k) : GTot Type0 = True inline_for_extraction let read_dsum_cases_t_if (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (k: dsum_known_key t) : Tot (if_combinator _ (read_dsum_cases_t_eq t f g k)) = fun cond (sv_true: cond_true cond -> Tot (read_dsum_cases_t t f g k)) (sv_false: cond_false cond -> Tot (read_dsum_cases_t t f g k)) #_ #_ input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let read_dsum_cases (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (leaf_reader (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (g32: leaf_reader g) (destr: dep_enum_destr _ (read_dsum_cases_t t f g)) (x: dsum_key t) : Tot (leaf_reader (parse_dsum_cases' t f g x)) = fun #_ #_ input pos -> match x with | Known k -> destr _ (read_dsum_cases_t_if t f g) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> read_dsum_cases' t f f32 g g32 (Known k)) k input pos | Unknown r -> read_dsum_cases' t f f32 g g32 (Unknown r) input pos #push-options "--z3rlimit 16" inline_for_extraction let read_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (p32: leaf_reader (parse_maybe_enum_key p (dsum_enum t))) (j: jumper p) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (f32: (x: dsum_known_key t) -> Tot (leaf_reader (dsnd (f x)))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (g32: leaf_reader g) (destr: dep_enum_destr _ (read_dsum_cases_t t f g)) : Tot (leaf_reader (parse_dsum t p f g)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_dsum t p f g) h input pos; parse_dsum_eq_ t p f g (bytes_of_slice_from h input pos); valid_facts (parse_maybe_enum_key p (dsum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_maybe_enum_key j (dsum_enum t) input pos in valid_facts (parse_dsum_cases' t f g k) h input pos' ; read_dsum_cases t f f32 g g32 destr k input pos' #pop-options inline_for_extraction let serialize32_dsum_type_of_tag (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (tg: dsum_key t) : Tot (serializer32 (serialize_dsum_type_of_tag t f sf g sg tg)) = match tg with | Known x' -> serialize32_ext (dsnd (f x')) (sf x') (sf32 x') (parse_dsum_type_of_tag t f g tg) () | Unknown x' -> serialize32_ext g sg sg32 (parse_dsum_type_of_tag t f g tg) () inline_for_extraction let serialize32_dsum_cases_aux (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (tg: dsum_key t) : Tot (serializer32 (serialize_dsum_cases t f sf g sg tg)) = [@inline_let] let _ = synth_dsum_case_injective t tg in [@inline_let] let _ = synth_dsum_case_inverse t tg in serialize32_synth (serialize32_dsum_type_of_tag t f sf sf32 sg32 tg) (synth_dsum_case t tg) (synth_dsum_case_recip t tg) (fun x -> synth_dsum_case_recip t tg x) () inline_for_extraction let serialize32_dsum_cases_t (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (sg: serializer g) (k: dsum_known_key t) : Tot Type = serializer32 (serialize_dsum_cases t f sf g sg (Known k)) let serialize32_dsum_cases_t_eq (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (sg: serializer g) (k: dsum_known_key t) (x y: serialize32_dsum_cases_t t f sf g sg k) : GTot Type0 = True inline_for_extraction let serialize32_dsum_cases_t_if (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (sg: serializer g) (k: dsum_known_key t) : Tot (if_combinator _ (serialize32_dsum_cases_t_eq t f sf g sg k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_dsum_cases_t t f sf g sg k))) (sv_false: (cond_false cond -> Tot (serialize32_dsum_cases_t t f sf g sg k))) x #rrel #rel output pos -> if cond then (sv_true () x output pos) else (sv_false () x output pos) inline_for_extraction let serialize32_dsum_cases (t: dsum) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (destr: dep_enum_destr _ (serialize32_dsum_cases_t t f sf g sg)) (tg: dsum_key t) : Tot (serializer32 (serialize_dsum_cases t f sf g sg tg)) = fun x #rrel #rel output pos -> match tg with | Known k -> destr _ (serialize32_dsum_cases_t_if t f sf g sg) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (fun k -> serialize32_dsum_cases_aux t f sf sf32 sg32 (Known k)) k x output pos | Unknown r -> serialize32_dsum_cases_aux t f sf sf32 sg32 (Unknown r) x output pos inline_for_extraction let serialize32_dsum (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_maybe_enum_key _ s (dsum_enum t))) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (sf: (x: dsum_known_key t) -> Tot (serializer (dsnd (f x)))) (sf32: (x: dsum_known_key t) -> Tot (serializer32 (sf x))) (#k': parser_kind) (#g: parser k' (dsum_type_of_unknown_tag t)) (#sg: serializer g) (sg32: serializer32 sg) (destr: dep_enum_destr _ (serialize32_dsum_cases_t t f sf g sg)) : Tot (serializer32 (serialize_dsum t s f sf g sg)) = fun x #_ #_ output pos -> [@inline_let] let _ = serialize_dsum_eq' t s f sf g sg x in let tg = dsum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_dsum_cases t f sf sf32 sg32 destr tg) tg x output pos let clens_dsum_tag (s: dsum) : Tot (clens (dsum_type s) (dsum_key s)) = { clens_cond = (fun _ -> True); clens_get = dsum_tag_of_data s; } let gaccessor_dsum_tag (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) : Tot (gaccessor (parse_dsum t p f g) (parse_maybe_enum_key p (dsum_enum t)) (clens_dsum_tag t)) = gaccessor_tagged_union_tag (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) inline_for_extraction let accessor_dsum_tag (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) : Tot (accessor (gaccessor_dsum_tag t p f g)) = accessor_tagged_union_tag (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) let clens_dsum_payload (s: dsum) (k: dsum_key s) : Tot (clens (dsum_type s) (dsum_type_of_tag s k)) = { clens_cond = (fun (x: dsum_type s) -> dsum_tag_of_data s x == k); clens_get = (fun (x: dsum_type s) -> synth_dsum_case_recip s k x <: Ghost (dsum_type_of_tag s k) (requires (dsum_tag_of_data s x == k)) (ensures (fun _ -> True))); } let clens_dsum_unknown_payload (s: dsum) : Tot (clens (dsum_type s) (dsum_type_of_unknown_tag s)) = { clens_cond = (fun (x: dsum_type s) -> Unknown? (dsum_tag_of_data s x)); clens_get = (fun (x: dsum_type s) -> synth_dsum_case_recip s (dsum_tag_of_data s x) x <: Ghost (dsum_type_of_unknown_tag s) (requires (Unknown? (dsum_tag_of_data s x))) (ensures (fun _ -> True))); } #push-options "--z3rlimit 16" let gaccessor_clens_dsum_payload' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) : Tot (gaccessor' (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k)) = fun (input: bytes) -> parse_dsum_eq3 t p f g input; let res = match parse p input with | Some (_, consumed) -> synth_dsum_case_inverse t k; synth_dsum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_dsum_case t k) (synth_dsum_case_recip t k) (); (consumed) | _ -> (0) // dummy in (res <: (res: _ { gaccessor_post' (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) input res } ))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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" }
false
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser ku (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> k: LowParse.Spec.Sum.dsum_key t -> sl: LowParse.Bytes.bytes -> sl': LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Sum.parse_dsum t p f g) (LowParse.Spec.Sum.parse_dsum_type_of_tag' t f g k) (LowParse.Low.Sum.clens_dsum_payload t k) sl /\ LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Sum.parse_dsum t p f g) (LowParse.Spec.Sum.parse_dsum_type_of_tag' t f g k) (LowParse.Low.Sum.clens_dsum_payload t k) sl' /\ LowParse.Spec.Base.injective_precond (LowParse.Spec.Sum.parse_dsum t p f g) sl sl') (ensures LowParse.Low.Sum.gaccessor_clens_dsum_payload' t p f g k sl == LowParse.Low.Sum.gaccessor_clens_dsum_payload' t p f g k sl')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.dsum_key", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse_injective", "Prims.unit", "LowParse.Spec.Sum.parse_dsum_kind", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.parse_dsum", "LowParse.Spec.Sum.parse_dsum_eq3", "Prims.l_and", "LowParse.Low.Base.Spec.gaccessor_pre", "LowParse.Spec.Sum.parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Sum.parse_dsum_type_of_tag'", "LowParse.Low.Sum.clens_dsum_payload", "LowParse.Spec.Base.injective_precond", "Prims.squash", "Prims.eq2", "Prims.nat", "LowParse.Low.Sum.gaccessor_clens_dsum_payload'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let gaccessor_clens_dsum_payload_injective (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#ku: parser_kind) (g: parser ku (dsum_type_of_unknown_tag t)) (k: dsum_key t) (sl sl': bytes) : Lemma (requires (gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl /\ gaccessor_pre (parse_dsum t p f g) (parse_dsum_type_of_tag' t f g k) (clens_dsum_payload t k) sl' /\ injective_precond (parse_dsum t p f g) sl sl')) (ensures (gaccessor_clens_dsum_payload' t p f g k sl == gaccessor_clens_dsum_payload' t p f g k sl')) =
parse_dsum_eq3 t p f g sl; parse_dsum_eq3 t p f g sl'; parse_injective (parse_dsum t p f g) sl sl'; parse_injective p sl sl'
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_le_4
val validate_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val validate_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 42, "end_line": 463, "start_col": 0, "start_line": 461 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.validate_bounded_int32_le'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let validate_bounded_int32_le_4 min32 max32 =
validate_bounded_int32_le' min32 max32 4
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_u32_le
val write_u32_le : leaf_writer_strong serialize_u32_le
val write_u32_le : leaf_writer_strong serialize_u32_le
let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 107, "end_line": 426, "start_col": 0, "start_line": 425 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_writer_strong LowParse.Spec.BoundedInt.serialize_u32_le
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Combinators.write_synth", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "LowParse.Low.BoundedInt.write_bounded_integer_le_4", "FStar.UInt32.t", "LowParse.Spec.BoundedInt.synth_u32_le", "LowParse.Spec.BoundedInt.synth_u32_le_recip", "Prims.eq2" ]
[]
false
false
false
true
false
let write_u32_le =
write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) ()
false
Lattice.fst
Lattice.interp
val interp (l: list eff_label) : annot
val interp (l: list eff_label) : annot
let interp (l : list eff_label) : annot = fun lab -> mem lab l
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 35, "start_col": 0, "start_line": 34 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list Lattice.eff_label -> Lattice.annot
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Lattice.eff_label", "FStar.List.Tot.Base.mem", "Prims.bool", "Lattice.annot" ]
[]
false
false
false
true
false
let interp (l: list eff_label) : annot =
fun lab -> mem lab l
false
Lattice.fst
Lattice.interp_at
val interp_at (l1 l2: list eff_label) (l: eff_label) : Lemma (interp (l1 @ l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1 @ l2) l)]
val interp_at (l1 l2: list eff_label) (l: eff_label) : Lemma (interp (l1 @ l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1 @ l2) l)]
let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 42, "start_col": 0, "start_line": 37 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Prims.list Lattice.eff_label -> l2: Prims.list Lattice.eff_label -> l: Lattice.eff_label -> FStar.Pervasives.Lemma (ensures Lattice.interp (l1 @ l2) l == (Lattice.interp l1 l || Lattice.interp l2 l)) [SMTPat (Lattice.interp (l1 @ l2) l)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Lattice.eff_label", "Lattice.interp_at", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.bool", "Lattice.interp", "FStar.List.Tot.Base.op_At", "Prims.op_BarBar", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec interp_at (l1 l2: list eff_label) (l: eff_label) : Lemma (interp (l1 @ l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1 @ l2) l)] =
match l1 with | [] -> () | _ :: l1 -> interp_at l1 l2 l
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_integer_le_2
val write_bounded_integer_le_2 : leaf_writer_strong (serialize_bounded_integer_le 2)
val write_bounded_integer_le_2 : leaf_writer_strong (serialize_bounded_integer_le 2)
let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 103, "end_line": 381, "start_col": 0, "start_line": 381 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_integer_le 2)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "LowParse.Low.BoundedInt.serialize32_bounded_integer_le_2" ]
[]
false
false
false
false
false
let write_bounded_integer_le_2 =
leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 ()
false
Lattice.fst
Lattice.subcomp
val subcomp (a: Type) (labs1 labs2: list eff_label) (f: repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True))
val subcomp (a: Type) (labs1 labs2: list eff_label) (f: repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True))
let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 100, "start_col": 0, "start_line": 94 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0) let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = let r = fun s0 -> match c s0 with | Some x, s1 -> f x s1 | None, s1 -> None, s1 in r
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> labs1: Prims.list Lattice.eff_label -> labs2: Prims.list Lattice.eff_label -> f: Lattice.repr a labs1 -> Prims.Pure (Lattice.repr a labs2)
Prims.Pure
[]
[]
[ "Prims.list", "Lattice.eff_label", "Lattice.repr", "Lattice.sublist", "Prims.l_True" ]
[]
false
false
false
false
false
let subcomp (a: Type) (labs1 labs2: list eff_label) (f: repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) =
f
false
Lattice.fst
Lattice.sublist_at
val sublist_at (l1 l2: list eff_label) : Lemma (sublist l1 (l1 @ l2) /\ sublist l2 (l1 @ l2)) [SMTPatOr [[SMTPat (sublist l1 (l1 @ l2))]; [SMTPat (sublist l2 (l1 @ l2))]]]
val sublist_at (l1 l2: list eff_label) : Lemma (sublist l1 (l1 @ l2) /\ sublist l2 (l1 @ l2)) [SMTPatOr [[SMTPat (sublist l1 (l1 @ l2))]; [SMTPat (sublist l2 (l1 @ l2))]]]
let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 68, "start_col": 0, "start_line": 61 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Prims.list Lattice.eff_label -> l2: Prims.list Lattice.eff_label -> FStar.Pervasives.Lemma (ensures Lattice.sublist l1 (l1 @ l2) /\ Lattice.sublist l2 (l1 @ l2)) [SMTPatOr [[SMTPat (Lattice.sublist l1 (l1 @ l2))]; [SMTPat (Lattice.sublist l2 (l1 @ l2))]]]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Lattice.eff_label", "Lattice.sublist_at", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "Lattice.sublist", "FStar.List.Tot.Base.op_At", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat_or", "FStar.Pervasives.smt_pat", "Prims.logical", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec sublist_at (l1 l2: list eff_label) : Lemma (sublist l1 (l1 @ l2) /\ sublist l2 (l1 @ l2)) [SMTPatOr [[SMTPat (sublist l1 (l1 @ l2))]; [SMTPat (sublist l2 (l1 @ l2))]]] =
match l1 with | [] -> () | _ :: l1 -> sublist_at l1 l2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_le_3
val validate_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val validate_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 42, "end_line": 459, "start_col": 0, "start_line": 457 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.validate_bounded_int32_le'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let validate_bounded_int32_le_3 min32 max32 =
validate_bounded_int32_le' min32 max32 3
false
Lattice.fst
Lattice.put
val put (s: state) : EFF unit [WR]
val put (s: state) : EFF unit [WR]
let put (s:state) : EFF unit [WR] = EFF?.reflect (fun _ -> (Some (), s))
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 137, "start_col": 0, "start_line": 136 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0) let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = let r = fun s0 -> match c s0 with | Some x, s1 -> f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun s0 -> (Some (f ()), s0) sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF int [RD] = EFF?.reflect (fun s0 -> (Some s0, s0))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Lattice.state -> Lattice.EFF Prims.unit
Lattice.EFF
[]
[]
[ "Lattice.state", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "Prims.unit", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "Prims.Cons", "Lattice.eff_label", "Lattice.WR", "Prims.Nil" ]
[]
false
true
false
false
false
let put (s: state) : EFF unit [WR] =
EFF?.reflect (fun _ -> (Some (), s))
false
Lattice.fst
Lattice.return
val return (a: Type) (x: a) : repr a []
val return (a: Type) (x: a) : repr a []
let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0)
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 80, "start_col": 0, "start_line": 78 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> x: a -> Lattice.repr a []
Prims.Tot
[ "total" ]
[]
[ "Lattice.state", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "Lattice.repr", "Prims.Nil", "Lattice.eff_label" ]
[]
false
false
false
true
false
let return (a: Type) (x: a) : repr a [] =
fun s0 -> (Some x, s0)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_le'
val validate_bounded_int32_le' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val validate_bounded_int32_le' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 447, "start_col": 0, "start_line": 429 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> sz: Prims.nat{sz == LowParse.Spec.BoundedInt.log256' (FStar.UInt32.v max32)} -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.nat", "Prims.eq2", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.validate_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Low.Combinators.validate_filter", "LowParse.Low.BoundedInt.validate_bounded_integer_le", "LowParse.Low.BoundedInt.read_bounded_integer_le", "Prims.op_Negation", "Prims.op_BarBar", "FStar.UInt32.lt", "Prims.bool", "FStar.UInt.uint_t", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) =
[@@ inline_let ]let min = U32.v min32 in [@@ inline_let ]let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x))) (fun x -> (x <: bounded_int32 min max)) ()
false
Lattice.fst
Lattice.interp_sublist
val interp_sublist (l1 l2: list eff_label) (l: eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)]
val interp_sublist (l1 l2: list eff_label) (l: eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)]
let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 59, "start_col": 0, "start_line": 53 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Prims.list Lattice.eff_label -> l2: Prims.list Lattice.eff_label -> l: Lattice.eff_label -> FStar.Pervasives.Lemma (requires Lattice.sublist l1 l2) (ensures Lattice.interp l1 l ==> Lattice.interp l2 l) [SMTPat (Lattice.interp l1 l); SMTPat (Lattice.sublist l1 l2)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Lattice.eff_label", "Lattice.interp_sublist", "Prims.unit", "Lattice.sublist", "Prims.squash", "Prims.l_imp", "Prims.b2t", "Lattice.interp", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.bool", "Prims.logical", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec interp_sublist (l1 l2: list eff_label) (l: eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] =
match l1 with | [] -> () | _ :: l1 -> interp_sublist l1 l2 l
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_le_1
val jump_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val jump_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 485, "start_col": 0, "start_line": 483 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.jump_bounded_int32_le'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let jump_bounded_int32_le_1 min32 max32 =
jump_bounded_int32_le' min32 max32 1
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_le_1
val validate_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val validate_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 42, "end_line": 451, "start_col": 0, "start_line": 449 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.validate_bounded_int32_le'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let validate_bounded_int32_le_1 min32 max32 =
validate_bounded_int32_le' min32 max32 1
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_le_3
val jump_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val jump_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 493, "start_col": 0, "start_line": 491 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.jump_bounded_int32_le'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let jump_bounded_int32_le_3 min32 max32 =
jump_bounded_int32_le' min32 max32 3
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_le_1
val write_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
val write_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 520, "start_col": 0, "start_line": 518 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32_le (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.write_bounded_int32_le'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le", "LowParse.Spec.BoundedInt.serialize_bounded_int32_le" ]
[]
false
false
false
false
false
let write_bounded_int32_le_1 min32 max32 =
write_bounded_int32_le' min32 max32 1
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_le_2
val write_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
val write_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 524, "start_col": 0, "start_line": 522 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32_le (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.write_bounded_int32_le'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le", "LowParse.Spec.BoundedInt.serialize_bounded_int32_le" ]
[]
false
false
false
false
false
let write_bounded_int32_le_2 min32 max32 =
write_bounded_int32_le' min32 max32 2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_le_1
val read_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val read_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let read_bounded_int32_le_1 min32 max32 = read_bounded_int32_le' min32 max32 1
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 556, "start_col": 0, "start_line": 554 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1 let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2 let write_bounded_int32_le_3 min32 max32 = write_bounded_int32_le' min32 max32 3 let write_bounded_int32_le_4 min32 max32 = write_bounded_int32_le' min32 max32 4 inline_for_extraction let read_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer_le sz) (in_bounds min max)) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 256 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Low.BoundedInt.read_bounded_int32_le'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let read_bounded_int32_le_1 min32 max32 =
read_bounded_int32_le' min32 max32 1
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_le'
val jump_bounded_int32_le' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val jump_bounded_int32_le' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) ()
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 481, "start_col": 0, "start_line": 466 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> sz: Prims.nat{sz == LowParse.Spec.BoundedInt.log256' (FStar.UInt32.v max32)} -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.nat", "Prims.eq2", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.jump_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Low.Combinators.jump_filter", "LowParse.Low.BoundedInt.jump_bounded_integer_le", "FStar.UInt.uint_t", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) (sz: nat{sz == log256' (U32.v max32)}) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) =
[@@ inline_let ]let min = U32.v min32 in [@@ inline_let ]let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) ()
false
Lattice.fst
Lattice.get
val get: Prims.unit -> EFF int [RD]
val get: Prims.unit -> EFF int [RD]
let get () : EFF int [RD] = EFF?.reflect (fun s0 -> (Some s0, s0))
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 134, "start_col": 0, "start_line": 133 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0) let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = let r = fun s0 -> match c s0 with | Some x, s1 -> f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun s0 -> (Some (f ()), s0) sub_effect PURE ~> EFF = lift_pure_eff
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Lattice.EFF Prims.int
Lattice.EFF
[]
[]
[ "Prims.unit", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "Prims.Cons", "Lattice.eff_label", "Lattice.RD", "Prims.Nil" ]
[]
false
true
false
false
false
let get () : EFF int [RD] =
EFF?.reflect (fun s0 -> (Some s0, s0))
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_le_4
val jump_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val jump_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 497, "start_col": 0, "start_line": 495 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.jump_bounded_int32_le'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let jump_bounded_int32_le_4 min32 max32 =
jump_bounded_int32_le' min32 max32 4
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_le_4
val read_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val read_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let read_bounded_int32_le_4 min32 max32 = read_bounded_int32_le' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 568, "start_col": 0, "start_line": 566 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1 let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2 let write_bounded_int32_le_3 min32 max32 = write_bounded_int32_le' min32 max32 3 let write_bounded_int32_le_4 min32 max32 = write_bounded_int32_le' min32 max32 4 inline_for_extraction let read_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer_le sz) (in_bounds min max)) () let read_bounded_int32_le_1 min32 max32 = read_bounded_int32_le' min32 max32 1 let read_bounded_int32_le_2 min32 max32 = read_bounded_int32_le' min32 max32 2 let read_bounded_int32_le_3 min32 max32 = read_bounded_int32_le' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.read_bounded_int32_le'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let read_bounded_int32_le_4 min32 max32 =
read_bounded_int32_le' min32 max32 4
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_le_3
val read_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val read_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let read_bounded_int32_le_3 min32 max32 = read_bounded_int32_le' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 564, "start_col": 0, "start_line": 562 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1 let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2 let write_bounded_int32_le_3 min32 max32 = write_bounded_int32_le' min32 max32 3 let write_bounded_int32_le_4 min32 max32 = write_bounded_int32_le' min32 max32 4 inline_for_extraction let read_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer_le sz) (in_bounds min max)) () let read_bounded_int32_le_1 min32 max32 = read_bounded_int32_le' min32 max32 1 let read_bounded_int32_le_2 min32 max32 = read_bounded_int32_le' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.read_bounded_int32_le'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let read_bounded_int32_le_3 min32 max32 =
read_bounded_int32_le' min32 max32 3
false
Lattice.fst
Lattice.lift_pure_eff
val lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True))
val lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True))
let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun s0 -> (Some (f ()), s0)
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 129, "start_col": 0, "start_line": 121 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0) let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = let r = fun s0 -> match c s0 with | Some x, s1 -> f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: Prims.pure_wp a -> f: (_: Prims.unit -> Prims.PURE a) -> Prims.Pure (Lattice.repr a [])
Prims.Pure
[]
[]
[ "Prims.pure_wp", "Prims.unit", "Lattice.state", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity", "Lattice.repr", "Prims.Nil", "Lattice.eff_label", "Prims.l_True" ]
[]
false
false
false
false
false
let lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun s0 -> (Some (f ()), s0)
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.jump_bounded_int32_le_2
val jump_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val jump_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 489, "start_col": 0, "start_line": 487 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.jumper (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.jump_bounded_int32_le'", "LowParse.Low.Base.jumper", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let jump_bounded_int32_le_2 min32 max32 =
jump_bounded_int32_le' min32 max32 2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_le_4
val write_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
val write_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
let write_bounded_int32_le_4 min32 max32 = write_bounded_int32_le' min32 max32 4
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 532, "start_col": 0, "start_line": 530 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1 let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2 let write_bounded_int32_le_3 min32 max32 = write_bounded_int32_le' min32 max32 3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 16777216 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32_le (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.write_bounded_int32_le'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le", "LowParse.Spec.BoundedInt.serialize_bounded_int32_le" ]
[]
false
false
false
false
false
let write_bounded_int32_le_4 min32 max32 =
write_bounded_int32_le' min32 max32 4
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.iand
val iand : a: Vale.Def.Words_s.natN n -> b: Vale.Def.Words_s.natN n -> Vale.Def.Words_s.natN n
let iand #n = Vale.Def.Types_s.iand #n
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 11, "start_col": 7, "start_line": 11 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want. unfold let pow2_128 = Vale.Def.Words_s.pow2_128
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.natN n -> b: Vale.Def.Words_s.natN n -> Vale.Def.Words_s.natN n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Def.Types_s.iand", "Vale.Def.Words_s.natN" ]
[]
false
false
false
false
false
let iand #n =
Vale.Def.Types_s.iand #n
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.validate_bounded_int32_le_2
val validate_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val validate_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 42, "end_line": 455, "start_col": 0, "start_line": 453 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.validator (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.validate_bounded_int32_le'", "LowParse.Low.Base.validator", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let validate_bounded_int32_le_2 min32 max32 =
validate_bounded_int32_le' min32 max32 2
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.serialize32_bounded_integer_le_4
val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4)
val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4)
let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 417, "start_col": 0, "start_line": 409 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_integer_le 4)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.BoundedInt.bounded_integer", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "Prims.unit", "LowParse.Low.Endianness.store_post_modifies", "FStar.UInt32.v", "FStar.Seq.Base.seq", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Endianness.le_to_n", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Endianness.store32_le_i", "LowParse.Low.Endianness.writable_store_pre", "LowParse.Spec.BoundedInt.bounded_integer_prop_equiv" ]
[]
false
false
false
false
false
let serialize32_bounded_integer_le_4 =
fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.pow2_128
val pow2_128 : Prims.int
let pow2_128 = Vale.Def.Words_s.pow2_128
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 9, "start_col": 7, "start_line": 9 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want.
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.pow2_128" ]
[]
false
false
false
true
false
let pow2_128 =
Vale.Def.Words_s.pow2_128
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_le_2
val read_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val read_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
let read_bounded_int32_le_2 min32 max32 = read_bounded_int32_le' min32 max32 2
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 560, "start_col": 0, "start_line": 558 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1 let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2 let write_bounded_int32_le_3 min32 max32 = write_bounded_int32_le' min32 max32 3 let write_bounded_int32_le_4 min32 max32 = write_bounded_int32_le' min32 max32 4 inline_for_extraction let read_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer_le sz) (in_bounds min max)) () let read_bounded_int32_le_1 min32 max32 = read_bounded_int32_le' min32 max32 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 256 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 65536 } -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.read_bounded_int32_le'", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le" ]
[]
false
false
false
false
false
let read_bounded_int32_le_2 min32 max32 =
read_bounded_int32_le' min32 max32 2
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.u64
val u64 : n: Lib.IntTypes.range_t Lib.IntTypes.U64 -> u29: Lib.IntTypes.uint64{Lib.IntTypes.v u29 == n}
let u64 = Lib.IntTypes.u64
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 15, "start_col": 7, "start_line": 15 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want. unfold let pow2_128 = Vale.Def.Words_s.pow2_128 unfold let nat64 = Vale.Def.Words_s.nat64 unfold let iand #n = Vale.Def.Types_s.iand #n unfold let size_nat = Lib.IntTypes.size_nat unfold let uint_v #t #l = Lib.IntTypes.uint_v #t #l
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Lib.IntTypes.range_t Lib.IntTypes.U64 -> u29: Lib.IntTypes.uint64{Lib.IntTypes.v u29 == n}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.u64" ]
[]
false
false
false
false
false
let u64 =
Lib.IntTypes.u64
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.nat64
val nat64 : Type0
let nat64 = Vale.Def.Words_s.nat64
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 10, "start_col": 7, "start_line": 10 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want.
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64" ]
[]
false
false
false
true
true
let nat64 =
Vale.Def.Words_s.nat64
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.read_bounded_int32_le_fixed_size
val read_bounded_int32_le_fixed_size (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (leaf_reader (parse_bounded_int32_le_fixed_size (U32.v min32) (U32.v max32)))
val read_bounded_int32_le_fixed_size (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (leaf_reader (parse_bounded_int32_le_fixed_size (U32.v min32) (U32.v max32)))
let read_bounded_int32_le_fixed_size min32 max32 = read_filter read_u32_le (in_bounds (U32.v min32) (U32.v max32))
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 65, "end_line": 576, "start_col": 0, "start_line": 574 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1 let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2 let write_bounded_int32_le_3 min32 max32 = write_bounded_int32_le' min32 max32 3 let write_bounded_int32_le_4 min32 max32 = write_bounded_int32_le' min32 max32 4 inline_for_extraction let read_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer_le sz) (in_bounds min max)) () let read_bounded_int32_le_1 min32 max32 = read_bounded_int32_le' min32 max32 1 let read_bounded_int32_le_2 min32 max32 = read_bounded_int32_le' min32 max32 2 let read_bounded_int32_le_3 min32 max32 = read_bounded_int32_le' min32 max32 3 let read_bounded_int32_le_4 min32 max32 = read_bounded_int32_le' min32 max32 4 let validate_bounded_int32_le_fixed_size min32 max32 = validate_filter (validate_u32_le ()) read_u32_le (in_bounds (U32.v min32) (U32.v max32)) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t{FStar.UInt32.v min32 <= FStar.UInt32.v max32} -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BoundedInt.parse_bounded_int32_le_fixed_size (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Low.Combinators.read_filter", "LowParse.Spec.Int.parse_u32_kind", "LowParse.Spec.BoundedInt.parse_u32_le", "LowParse.Low.BoundedInt.read_u32_le", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BoundedInt.parse_bounded_int32_fixed_size_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le_fixed_size" ]
[]
false
false
false
false
false
let read_bounded_int32_le_fixed_size min32 max32 =
read_filter read_u32_le (in_bounds (U32.v min32) (U32.v max32))
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.uint8
val uint8 : Type0
let uint8 = Lib.IntTypes.uint8
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 14, "start_col": 7, "start_line": 14 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want. unfold let pow2_128 = Vale.Def.Words_s.pow2_128 unfold let nat64 = Vale.Def.Words_s.nat64 unfold let iand #n = Vale.Def.Types_s.iand #n unfold let size_nat = Lib.IntTypes.size_nat
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.uint8" ]
[]
false
false
false
true
true
let uint8 =
Lib.IntTypes.uint8
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.uint_v
val uint_v : u28: Lib.IntTypes.int_t t l -> x: Prims.int{Lib.IntTypes.range x t}
let uint_v #t #l = Lib.IntTypes.uint_v #t #l
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 13, "start_col": 7, "start_line": 13 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want. unfold let pow2_128 = Vale.Def.Words_s.pow2_128 unfold let nat64 = Vale.Def.Words_s.nat64 unfold let iand #n = Vale.Def.Types_s.iand #n
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
u28: Lib.IntTypes.int_t t l -> x: Prims.int{Lib.IntTypes.range x t}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.inttype", "Prims.b2t", "Lib.IntTypes.unsigned", "Lib.IntTypes.secrecy_level", "Lib.IntTypes.uint_v", "Lib.IntTypes.int_t", "Prims.int", "Lib.IntTypes.range" ]
[]
false
false
false
false
false
let uint_v #t #l =
Lib.IntTypes.uint_v #t #l
false
LowParse.Low.BoundedInt.fst
LowParse.Low.BoundedInt.write_bounded_int32_le_3
val write_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
val write_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
let write_bounded_int32_le_3 min32 max32 = write_bounded_int32_le' min32 max32 3
{ "file_name": "src/lowparse/LowParse.Low.BoundedInt.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 528, "start_col": 0, "start_line": 526 }
module LowParse.Low.BoundedInt open LowParse.Low.Combinators module Seq = FStar.Seq module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module E = LowParse.Endianness.BitFields module BF = LowParse.BitFields module LE = LowParse.Low.Endianness module Cast = FStar.Int.Cast friend LowParse.Spec.BoundedInt inline_for_extraction let mul256 (x: U16.t) : Tot (y: U32.t { U32.v y == 256 `Prims.op_Multiply` U16.v x }) = assert_norm (pow2 8 == 256); FStar.Math.Lemmas.pow2_lt_compat 32 24; FStar.Math.Lemmas.pow2_lt_compat 24 16; FStar.Math.Lemmas.pow2_lt_compat 16 8; FStar.Math.Lemmas.pow2_plus 8 16; FStar.Math.Lemmas.small_mod (U16.v x `Prims.op_Multiply` 256) (pow2 32); FStar.UInt.shift_left_value_lemma #32 (U16.v x) 8; Cast.uint16_to_uint32 x `U32.shift_left` 8ul inline_for_extraction let div256 (x: U32.t) : Tot (y: U32.t { U32.v y == U32.v x / 256 }) = assert_norm (pow2 8 == 256); FStar.UInt.shift_right_value_lemma #32 (U32.v x) 8; x `U32.shift_right` 8ul (* bounded integers *) let read_bounded_integer_1 () = [@inline_let] let _ = decode_bounded_integer_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (decode_bounded_integer 1) () (fun #rrel #rel input pos -> let h = HST.get () in E.index_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 1)); let r = B.index input pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_2 () = [@inline_let] let _ = decode_bounded_integer_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (decode_bounded_integer 2) () (fun #rrel #rel input pos -> let h = HST.get () in let r = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_3 () = [@inline_let] let _ = decode_bounded_integer_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (decode_bounded_integer 3) () (fun #rrel #rel input pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)) 2; E.reveal_be_to_n (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); let lo = B.index input (pos `U32.add` 2ul) in let hi = LE.load16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 2)); E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_4 () = [@inline_let] let _ = decode_bounded_integer_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (decode_bounded_integer 4) () (fun #rrel #rel input pos -> let h = HST.get () in E.lemma_be_to_n_is_bounded (Seq.slice (B.as_seq h input) (U32.v pos) (U32.v pos + 4)); LE.load32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) input pos ) let read_bounded_integer_ct i #rrel #rel sl pos = let h = HST.get () in valid_total_constant_size h (parse_bounded_integer (U32.v i)) (U32.v i) sl pos; valid_facts (parse_bounded_integer (U32.v i)) h sl pos; valid_total_constant_size h parse_u32 4 sl pos; valid_facts parse_u32 h sl pos; decode_bounded_integer_injective (U32.v i); parse_u32_spec (bytes_of_slice_from h sl pos); E.bitfield_be_to_n_slice (Seq.slice (bytes_of_slice_from h sl pos) 0 4) 0 (U32.v i); let r = LE.load32_be_i sl.base pos in BF.uint32.BF.get_bitfield_gen r (8ul `U32.mul` (4ul `U32.sub` i)) 32ul let serialize32_bounded_integer_1 () = fun (v: bounded_integer 1) #rrel #rel out pos -> bounded_integer_prop_equiv 1 v; E.index_n_to_be 1 (U32.v v) 0; mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 v); 1ul let serialize32_bounded_integer_2 () = fun (v: bounded_integer 2) #rrel #rel out pos -> bounded_integer_prop_equiv 2 v; let h = HST.get () in let v' = (Cast.uint32_to_uint16 v) in LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v'; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v v') h h'; 2ul #push-options "--z3rlimit 16" let serialize32_bounded_integer_3 () = fun (v: bounded_integer 3) #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_be 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) (pos `U32.add` 2ul) lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos) (U32.v pos + 2); LE.writable_store_pre out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1; LE.store16_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos) 2 (fun s -> E.be_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out (pos `U32.add` 2ul) (pos `U32.add` 3ul) (B.loc_buffer_from_to out pos (pos `U32.add` 2ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos + 2) (U32.v pos + 3) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let serialize32_bounded_integer_4 () = fun (v: bounded_integer 4) #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h; LE.store32_be_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.be_to_n s == U32.v v) h h'; 4ul inline_for_extraction let write_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_1 min32 max32 = write_bounded_int32' min32 max32 1 let write_bounded_int32_2 min32 max32 = write_bounded_int32' min32 max32 2 let write_bounded_int32_3 min32 max32 = write_bounded_int32' min32 max32 3 let write_bounded_int32_4 min32 max32 = write_bounded_int32' min32 max32 4 inline_for_extraction let read_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_reader (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in read_inline_synth (parse_filter (parse_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (read_filter (read_bounded_integer sz) (in_bounds min max)) () let read_bounded_int32_1 min32 max32 = read_bounded_int32' min32 max32 1 let read_bounded_int32_2 min32 max32 = read_bounded_int32' min32 max32 2 let read_bounded_int32_3 min32 max32 = read_bounded_int32' min32 max32 3 let read_bounded_int32_4 min32 max32 = read_bounded_int32' min32 max32 4 inline_for_extraction let validate_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer sz) (read_bounded_integer sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_1 min32 max32 = validate_bounded_int32' min32 max32 1 let validate_bounded_int32_2 min32 max32 = validate_bounded_int32' min32 max32 2 let validate_bounded_int32_3 min32 max32 = validate_bounded_int32' min32 max32 3 let validate_bounded_int32_4 min32 max32 = validate_bounded_int32' min32 max32 4 inline_for_extraction let jump_bounded_int32' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32 (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_1 min32 max32 = jump_bounded_int32' min32 max32 1 let jump_bounded_int32_2 min32 max32 = jump_bounded_int32' min32 max32 2 let jump_bounded_int32_3 min32 max32 = jump_bounded_int32' min32 max32 3 let jump_bounded_int32_4 min32 max32 = jump_bounded_int32' min32 max32 4 let read_bounded_integer_le_1 = [@inline_let] let _ = bounded_integer_of_le_injective 1 in make_total_constant_size_reader 1 1ul #(bounded_integer 1) (bounded_integer_of_le 1) () (fun #rrel #rel b pos -> let h = HST.get () in E.index_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)) 0; E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 1)); let r = B.index b pos in Cast.uint8_to_uint32 r ) let read_bounded_integer_le_2 = [@inline_let] let _ = bounded_integer_of_le_injective 2 in make_total_constant_size_reader 2 2ul #(bounded_integer 2) (bounded_integer_of_le 2) () (fun #rrel #rel b pos -> let h = HST.get () in let r = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 2)); Cast.uint16_to_uint32 r ) #push-options "--z3rlimit 16" let read_bounded_integer_le_3 = [@inline_let] let _ = bounded_integer_of_le_injective 3 in make_total_constant_size_reader 3 3ul #(bounded_integer 3) (bounded_integer_of_le 3) () (fun #rrel #rel b pos -> let h = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)) 1; E.reveal_le_to_n (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); let lo = B.index b pos in let hi = LE.load16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b (pos `U32.add` 1ul) in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos + 1) (U32.v pos + 3)); E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 3)); assert_norm (pow2 8 == 256); Cast.uint8_to_uint32 lo `U32.add` (mul256 hi) ) #pop-options let read_bounded_integer_le_4 = [@inline_let] let _ = bounded_integer_of_le_injective 4 in make_total_constant_size_reader 4 4ul #(bounded_integer 4) (bounded_integer_of_le 4) () (fun #rrel #rel b pos -> let h = HST.get () in E.lemma_le_to_n_is_bounded (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)); LE.load32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos ) let read_u16_le = [@inline_let] let _ = synth_u16_le_injective in read_inline_synth' _ synth_u16_le read_bounded_integer_le_2 () let read_u32_le = read_inline_synth' _ synth_u32_le read_bounded_integer_le_4 () let serialize32_bounded_integer_le_1 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 1 x; E.index_n_to_le 1 (U32.v x) 0; mbuffer_upd b (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 1)) pos (Cast.uint32_to_uint8 x); 1ul let write_bounded_integer_le_1 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_1 () #push-options "--z3rlimit 20" let serialize32_bounded_integer_le_2 = fun x #rrel #rel b pos -> bounded_integer_prop_equiv 2 x; let h = HST.get () in let x' = (Cast.uint32_to_uint16 x) in LE.writable_store_pre b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) b pos x'; let h' = HST.get () in LE.store_post_modifies b (U32.v pos) 2 (fun s -> E.le_to_n s == U16.v x') h h'; 2ul #pop-options let write_bounded_integer_le_2 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_2 () #push-options "--z3rlimit 16" let serialize32_bounded_integer_le_3 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 3 v; E.reveal_n_to_le 3 (U32.v v); assert_norm (pow2 8 == 256); let lo = Cast.uint32_to_uint8 v in mbuffer_upd out (Ghost.hide (U32.v pos)) (Ghost.hide (U32.v pos + 3)) pos lo; let hi' = div256 v in FStar.Math.Lemmas.small_mod (U32.v hi') (pow2 16); let hi = Cast.uint32_to_uint16 hi' in let h1 = HST.get () in LE.writable_weaken out (U32.v pos) (U32.v pos + 3) h1 (U32.v pos + 1) (U32.v pos + 3); LE.writable_store_pre out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1; LE.store16_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out (pos `U32.add` 1ul) hi; let h2 = HST.get () in LE.store_post_modifies out (U32.v pos + 1) 2 (fun s -> E.le_to_n s == U16.v hi) h1 h2; B.modifies_buffer_from_to_elim out pos (pos `U32.add` 1ul) (B.loc_buffer_from_to out (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h1 h2; assert (Seq.slice (B.as_seq h2 out) (U32.v pos) (U32.v pos + 1) `Seq.equal` Seq.create 1 lo); 3ul #pop-options let write_bounded_integer_le_3 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_3 () let serialize32_bounded_integer_le_4 = fun v #rrel #rel out pos -> bounded_integer_prop_equiv 4 v; let h = HST.get () in LE.writable_store_pre out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h; LE.store32_le_i (* #(Ghost.hide rrel) #(Ghost.hide rel) *) out pos v; let h' = HST.get () in LE.store_post_modifies out (U32.v pos) 4 (fun s -> E.le_to_n s == U32.v v) h h'; 4ul let write_bounded_integer_le_4 = leaf_writer_strong_of_serializer32 serialize32_bounded_integer_le_4 () let write_u16_le = [@inline_let] let _ = synth_u16_le_injective; synth_u16_le_inverse in write_synth write_bounded_integer_le_2 synth_u16_le synth_u16_le_recip (fun x -> synth_u16_le_recip x) () let write_u32_le = write_synth write_bounded_integer_le_4 synth_u32_le synth_u32_le_recip (fun x -> synth_u32_le_recip x) () inline_for_extraction let validate_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (validator (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in validate_synth (validate_filter (validate_bounded_integer_le sz) (read_bounded_integer_le sz) (in_bounds min max) (fun x -> not (x `U32.lt` min32 || max32 `U32.lt` x)) ) (fun x -> (x <: bounded_int32 min max)) () let validate_bounded_int32_le_1 min32 max32 = validate_bounded_int32_le' min32 max32 1 let validate_bounded_int32_le_2 min32 max32 = validate_bounded_int32_le' min32 max32 2 let validate_bounded_int32_le_3 min32 max32 = validate_bounded_int32_le' min32 max32 3 let validate_bounded_int32_le_4 min32 max32 = validate_bounded_int32_le' min32 max32 4 inline_for_extraction let jump_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (jumper (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in jump_synth (jump_filter (jump_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) () let jump_bounded_int32_le_1 min32 max32 = jump_bounded_int32_le' min32 max32 1 let jump_bounded_int32_le_2 min32 max32 = jump_bounded_int32_le' min32 max32 2 let jump_bounded_int32_le_3 min32 max32 = jump_bounded_int32_le' min32 max32 3 let jump_bounded_int32_le_4 min32 max32 = jump_bounded_int32_le' min32 max32 4 inline_for_extraction let write_bounded_int32_le' (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) (sz: nat { sz == log256' (U32.v max32) }) : Tot (leaf_writer_strong (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = [@inline_let] let min = U32.v min32 in [@inline_let] let max = U32.v max32 in write_synth (write_filter (write_bounded_integer_le sz) (in_bounds min max)) (fun x -> (x <: bounded_int32 min max)) (fun x -> x) (fun x -> x) () let write_bounded_int32_le_1 min32 max32 = write_bounded_int32_le' min32 max32 1 let write_bounded_int32_le_2 min32 max32 = write_bounded_int32_le' min32 max32 2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BoundedInt.fst.checked", "LowParse.Low.Endianness.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Low.BoundedInt.fst" }
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Low.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "LowParse.Endianness.BitFields", "short_module": "E" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 65536 <= FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 16777216 } -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BoundedInt.serialize_bounded_int32_le (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "LowParse.Low.BoundedInt.write_bounded_int32_le'", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BoundedInt.parse_bounded_int32_le", "LowParse.Spec.BoundedInt.serialize_bounded_int32_le" ]
[]
false
false
false
false
false
let write_bounded_int32_le_3 min32 max32 =
write_bounded_int32_le' min32 max32 3
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.repeati
val repeati : n: Prims.nat -> f: (i: Prims.nat{i < n} -> _: _ -> _) -> acc0: _ -> _
let repeati = Lib.LoopCombinators.repeati
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 17, "start_col": 7, "start_line": 17 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want. unfold let pow2_128 = Vale.Def.Words_s.pow2_128 unfold let nat64 = Vale.Def.Words_s.nat64 unfold let iand #n = Vale.Def.Types_s.iand #n unfold let size_nat = Lib.IntTypes.size_nat unfold let uint_v #t #l = Lib.IntTypes.uint_v #t #l unfold let uint8 = Lib.IntTypes.uint8 unfold let u64 = Lib.IntTypes.u64
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> f: (i: Prims.nat{i < n} -> _: _ -> _) -> acc0: _ -> _
Prims.Tot
[ "total" ]
[]
[ "Lib.LoopCombinators.repeati", "Prims.nat", "Prims.b2t", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let repeati =
Lib.LoopCombinators.repeati
false
Lattice.fst
Lattice.raise
val raise: #a: _ -> Prims.unit -> EFF a [EXN]
val raise: #a: _ -> Prims.unit -> EFF a [EXN]
let raise #a () : EFF a [EXN] = EFF?.reflect (fun s0 -> (None, s0))
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 140, "start_col": 0, "start_line": 139 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0) let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = let r = fun s0 -> match c s0 with | Some x, s1 -> f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun s0 -> (Some (f ()), s0) sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF int [RD] = EFF?.reflect (fun s0 -> (Some s0, s0)) let put (s:state) : EFF unit [WR] = EFF?.reflect (fun _ -> (Some (), s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Lattice.EFF a
Lattice.EFF
[]
[]
[ "Prims.unit", "Lattice.state", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "Prims.Cons", "Lattice.eff_label", "Lattice.EXN", "Prims.Nil" ]
[]
false
true
false
false
false
let raise #a () : EFF a [EXN] =
EFF?.reflect (fun s0 -> (None, s0))
false
Vale.Poly1305.Equiv.fst
Vale.Poly1305.Equiv.size_nat
val size_nat : Type0
let size_nat = Lib.IntTypes.size_nat
{ "file_name": "vale/code/crypto/poly1305/Vale.Poly1305.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 12, "start_col": 7, "start_line": 12 }
module Vale.Poly1305.Equiv open FStar.Mul module BSeq = Lib.ByteSequence // REVIEW: S and V use different smtencoding flags, // so some equalities between S and V definitions aren't as obvious to Z3 as we might want. unfold let pow2_128 = Vale.Def.Words_s.pow2_128 unfold let nat64 = Vale.Def.Words_s.nat64
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Math.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Impl.Poly1305.Lemmas.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Poly1305.Equiv.fst" }
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Poly1305.Spec_s", "short_module": "V" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_nat" ]
[]
false
false
false
true
true
let size_nat =
Lib.IntTypes.size_nat
false
Lattice.fst
Lattice.test1
val test1 (x y: int) : EFF int [EXN; RD; WR]
val test1 (x y: int) : EFF int [EXN; RD; WR]
let test1 (x y : int) : EFF int [EXN; RD; WR] = let z = get () in if x + z > 0 then raise () else (put 42; y - z)
{ "file_name": "examples/layeredeffects/Lattice.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 152, "start_col": 0, "start_line": 148 }
module Lattice open FStar.Tactics.V2 open FStar.List.Tot // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = | RD | WR //| DIV | EXN // DONE: split ST into READ/WRITE with relational prop on abides // ^ this was incredibly easy // DONE add specs (see LatticeSpec.fst) type annot = eff_label -> bool type state = int type repr0 (a:Type u#aa) : Type u#aa = state -> Tot (option a & state) let abides #a (f : repr0 a) (ann:annot) : prop = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 type repr (a:Type) (labs : list eff_label) : Type = r:(repr0 a){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun s0 -> (Some x, s0) let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = let r = fun s0 -> match c s0 with | Some x, s1 -> f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun s0 -> (Some (f ()), s0) sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF int [RD] = EFF?.reflect (fun s0 -> (Some s0, s0)) let put (s:state) : EFF unit [WR] = EFF?.reflect (fun _ -> (Some (), s)) let raise #a () : EFF a [EXN] = EFF?.reflect (fun s0 -> (None, s0)) let test0 (x y : int) : EFF int [RD; EXN] = let z = get () in if x + z > 0 then raise () else y - z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Lattice.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> y: Prims.int -> Lattice.EFF Prims.int
Lattice.EFF
[]
[]
[ "Prims.int", "Prims.op_GreaterThan", "Prims.op_Addition", "Lattice.raise", "Prims.bool", "Prims.op_Subtraction", "Prims.unit", "Lattice.put", "Lattice.get", "Prims.Cons", "Lattice.eff_label", "Lattice.EXN", "Lattice.RD", "Lattice.WR", "Prims.Nil" ]
[]
false
true
false
false
false
let test1 (x y: int) : EFF int [EXN; RD; WR] =
let z = get () in if x + z > 0 then raise () else (put 42; y - z)
false