file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.unit_tm
val unit_tm : FStar.Stubs.Reflection.Types.term
let unit_tm = R.pack_ln (R.Tv_FVar unit_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 42, "start_col": 0, "start_line": 42 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.unit_fv" ]
[]
false
false
false
true
false
let unit_tm =
R.pack_ln (R.Tv_FVar unit_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.unit_fv
val unit_fv : FStar.Stubs.Reflection.Types.fv
let unit_fv = R.pack_fv unit_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 41, "start_col": 0, "start_line": 41 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.unit_lid" ]
[]
false
false
false
true
false
let unit_fv =
R.pack_fv unit_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.bool_tm
val bool_tm : FStar.Stubs.Reflection.Types.term
let bool_tm = R.pack_ln (R.Tv_FVar bool_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 44, "start_col": 0, "start_line": 44 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.bool_fv" ]
[]
false
false
false
true
false
let bool_tm =
R.pack_ln (R.Tv_FVar bool_fv)
false
MerkleTree.Low.fst
MerkleTree.Low.mt_flush_to_pre
val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True))
val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True))
let mt_flush_to_pre mt idx = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_flush_to_pre_nst mtv idx
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 29, "end_line": 2432, "start_col": 0, "start_line": 2428 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after))))) #push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1" let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) #pop-options // For given a target index `k`, the number of elements (in the tree) `j`, // and a boolean flag (to check the existence of rightmost hashes), we can // calculate a required Merkle path length. // // `mt_path_length` is a postcondition of `mt_get_path`, and a precondition // of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`. private val mt_path_length_step: k:index_t -> j:index_t{k <= j} -> actd:bool -> Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd}) let mt_path_length_step k j actd = if j = 0ul then 0ul else (if k % 2ul = 0ul then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul) else 1ul) private inline_for_extraction val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j)) #push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1" let rec mt_path_length lv k j actd = if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd) #pop-options val mt_get_path_length: mtr:HH.rid -> p:const_path_p -> HST.ST uint32_t (requires (fun h0 -> path_safe h0 mtr (CB.cast p))) (ensures (fun h0 _ h1 -> True)) let mt_get_path_length mtr p = let pd = !*(CB.cast p) in V.size_of (Path?.hashes pd) private inline_for_extraction val mt_make_path_step: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\ V.size_of (phashes h1 p) <= lv + 2ul /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_make_path_step (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2" let mt_make_path_step #hsz lv mtr hs rhs i j k p actd = let pth = !*p in let hh0 = HST.get () in let ofs = offset_of i in if k % 2ul = 1ul then begin hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs)))); assert(Path?.hash_size pth = hsz); mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs)) end else begin if k = j then () else if k + 1ul = j then (if actd then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv))); mt_path_insert mtr p (V.index rhs lv))) else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs)))); mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs))) end #pop-options private inline_for_extraction val mt_get_path_step_pre_nst: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:path -> i:uint32_t -> Tot bool let mt_get_path_step_pre_nst #hsz mtr p i = i < V.size_of (Path?.hashes p) val mt_get_path_step_pre: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST bool (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ mt_get_path_step_pre_nst #hsz mtr pv i))) (ensures (fun _ _ _ -> True)) let mt_get_path_step_pre #hsz mtr p i = let p = CB.cast p in mt_get_path_step_pre_nst #hsz mtr !*p i val mt_get_path_step: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST (hash #hsz) (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ i < V.size_of (Path?.hashes pv)))) (ensures (fun h0 r h1 -> True )) let mt_get_path_step #hsz mtr p i = let pd = !*(CB.cast p) in V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i private val mt_get_path_: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length lv k j actd /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2" let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd = let hh0 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; let ofs = offset_of i in if j = 0ul then () else (mt_make_path_step lv mtr hs rhs i j k p actd; let hh1 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (lift_path hh1 mtr p) (MTH.mt_make_path_step (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd)); RV.rv_inv_preserved hs (path_loc p) hh0 hh1; RV.rv_inv_preserved rhs (path_loc p) hh0 hh1; RV.as_seq_preserved hs (path_loc p) hh0 hh1; RV.as_seq_preserved rhs (path_loc p) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1; assert (mt_safe_elts hh1 lv hs i j); mt_safe_elts_rec hh1 lv hs i j; mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p (if j % 2ul = 0ul then actd else true); let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv + 1) (RV.as_seq hh1 hs) (RV.as_seq hh1 rhs) (U32.v i / 2) (U32.v j / 2) (U32.v k / 2) (lift_path hh1 mtr p) (if U32.v j % 2 = 0 then actd else true))); assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd))) #pop-options private inline_for_extraction val mt_get_path_pre_nst: mtv:merkle_tree -> idx:offset_t -> p:path -> root:(hash #(MT?.hash_size mtv)) -> Tot bool let mt_get_path_pre_nst mtv idx p root = offsets_connect (MT?.offset mtv) idx && Path?.hash_size p = MT?.hash_size mtv && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in MT?.i mtv <= idx && idx < MT?.j mtv && V.size_of (Path?.hashes p) = 0ul) val mt_get_path_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:const_path_p -> root:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let dmt = B.get h0 mt 0 in let dp = B.get h0 p 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ Path?.hash_size dp = (Ghost.reveal hsz) /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun _ _ _ -> True)) let mt_get_path_pre #_ mt idx p root = let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_get_path_pre_nst mtv idx !*p root val mt_get_path_loc_union_helper: l1:loc -> l2:loc -> Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2) let mt_get_path_loc_union_helper l1 l2 = () // Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost // hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree // to the output path. #push-options "--z3rlimit 60" val mt_get_path: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:path_p -> root:hash #hsz -> HST.ST index_t (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let idx = split_offset (MT?.offset mtv0) idx in MT?.hash_size mtv0 = Ghost.reveal hsz /\ MT?.hash_size mtv1 = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\ // memory safety modifies (loc_union (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) h0 h1 /\ mt_safe h1 mt /\ path_safe h1 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h1 root /\ V.size_of (phashes h1 p) == 1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\ // correctness (let sj, sp, srt = MTH.mt_get_path (mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in sj == U32.v (MT?.j mtv1) /\ S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\ srt == Rgl?.r_repr (hreg hsz) h1 root))) #pop-options #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" let mt_get_path #hsz mt idx p root = let ncmt = CB.cast mt in let mtframe = B.frameOf ncmt in let hh0 = HST.get () in mt_get_root mt root; let mtv = !*ncmt in let hsz = MT?.hash_size mtv in let hh1 = HST.get () in path_safe_init_preserved mtframe p (B.loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) hh0 hh1; assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) == (mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root)); assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty); let idx = split_offset (MT?.offset mtv) idx in let i = MT?.i mtv in let ofs = offset_of (MT?.i mtv) in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in assert (mt_safe_elts hh1 0ul hs i j); assert (V.size_of (V.get hh1 hs 0ul) == j - ofs); assert (idx < j); hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs); hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs); hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs); let ih = V.index (V.index hs 0ul) (idx - ofs) in mt_path_insert #hsz mtframe p ih; let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtframe p) (MTH.path_insert (lift_path hh1 mtframe p) (S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs)))); Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2; mt_safe_preserved ncmt (path_loc p) hh1 hh2; mt_preserved ncmt (path_loc p) hh1 hh2; assert (V.size_of (phashes hh2 p) == 1ul); mt_get_path_ 0ul mtframe hs rhs i j idx p false; let hh3 = HST.get () in // memory safety mt_get_path_loc_union_helper (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p); Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3; mt_safe_preserved ncmt (path_loc p) hh2 hh3; mt_preserved ncmt (path_loc p) hh2 hh3; assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); assert (S.length (lift_path #hsz hh3 mtframe p) == S.length (lift_path #hsz hh2 mtframe p) + MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false); assert (modifies (loc_union (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) hh0 hh3); assert (mt_safe hh3 ncmt); assert (path_safe hh3 mtframe p); assert (Rgl?.r_inv (hreg hsz) hh3 root); assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); // correctness mt_safe_elts_spec hh2 0ul hs i j; assert (S.equal (lift_path hh3 mtframe p) (MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs) (U32.v i) (U32.v j) (U32.v idx) (lift_path hh2 mtframe p) false)); assert (MTH.mt_get_path (mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) == (U32.v (MT?.j (B.get hh3 ncmt 0)), lift_path hh3 mtframe p, Rgl?.r_repr (hreg hsz) hh3 root)); j #pop-options /// Flushing private val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) #push-options "--initial_fuel 2 --max_fuel 2" let mt_flush_to_modifies_rec_helper #hsz lv hs h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val mt_flush_to_: hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> pi:index_t -> i:index_t{i >= pi} -> j:Ghost.erased index_t{ Ghost.reveal j >= i && U32.v (Ghost.reveal j) < pow2 (32 - U32.v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs pi (Ghost.reveal j))) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1 /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i (Ghost.reveal j) /\ // correctness (mt_safe_elts_spec h0 lv hs pi (Ghost.reveal j); S.equal (RV.as_seq h1 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq h0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))))) (decreases (U32.v i)) #restart-solver #push-options "--z3rlimit 1500 --fuel 1 --ifuel 0" let rec mt_flush_to_ hsz lv hs pi i j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs pi (Ghost.reveal j); V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); let oi = offset_of i in let opi = offset_of pi in if oi = opi then mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j) else begin /// 1) Flush hashes at the level `lv`, where the new vector is /// not yet connected to `hs`. let ofs = oi - opi in let hvec = V.index hs lv in let flushed:(rvector (hreg hsz)) = rv_flush_inplace hvec ofs in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) flushed); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of flushed == Ghost.reveal j - offset_of i); // head updated mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 flushed) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) (U32.v ofs) (S.length (RV.as_seq hh0 (V.get hh0 hs lv))))); /// 2) Assign the flushed vector to `hs` at the level `lv`. RV.assign hs lv flushed; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == Ghost.reveal j - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector flushed) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector flushed) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 flushed) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 flushed); // if `lv = 31` then `pi <= i <= j < 2` thus `oi = opi`, // contradicting the branch. assert (lv + 1ul < merkle_tree_size_lg); assert (U32.v (Ghost.reveal j / 2ul) < pow2 (32 - U32.v (lv + 1ul))); assert (RV.rv_inv hh2 hs); assert (mt_safe_elts hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)); /// 3) Recursion mt_flush_to_ hsz (lv + 1ul) hs (pi / 2ul) (i / 2ul) (Ghost.hide (Ghost.reveal j / 2ul)); let hh3 = HST.get () in // 3-0) Memory safety brought from the postcondition of the recursion assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == Ghost.reveal j - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i (Ghost.reveal j); assert (mt_safe_elts hh3 lv hs i (Ghost.reveal j)); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv + 1) (RV.as_seq hh2 hs) (U32.v pi / 2) (U32.v i / 2) (U32.v (Ghost.reveal j) / 2))); mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j); MTH.mt_flush_to_rec (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))) end #pop-options // `mt_flush_to` flushes old hashes in the Merkle tree. It removes hash elements // from `MT?.i` to **`offset_of (idx - 1)`**, but maintains the tree structure, // i.e., the tree still holds some old internal hashes (compressed from old // hashes) which are required to generate Merkle paths for remaining hashes. // // Note that `mt_flush_to` (and `mt_flush`) always remain at least one base hash // elements. If there are `MT?.j` number of elements in the tree, because of the // precondition `MT?.i <= idx < MT?.j` we still have `idx`-th element after // flushing. private inline_for_extraction val mt_flush_to_pre_nst: mtv:merkle_tree -> idx:offset_t -> Tot bool let mt_flush_to_pre_nst mtv idx = offsets_connect (MT?.offset mtv) idx && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in idx >= MT?.i mtv && idx < MT?.j mtv) val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.const_mt_p -> idx: MerkleTree.Low.offset_t -> FStar.HyperStack.ST.ST Prims.bool
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.const_mt_p", "MerkleTree.Low.offset_t", "MerkleTree.Low.mt_flush_to_pre_nst", "Prims.bool", "MerkleTree.Low.merkle_tree", "LowStar.BufferOps.op_Bang_Star", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.ConstBuffer.cast" ]
[]
false
true
false
false
false
let mt_flush_to_pre mt idx =
let mt = CB.cast mt in let h0 = HST.get () in let mtv = !*mt in mt_flush_to_pre_nst mtv idx
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.bool_fv
val bool_fv : FStar.Stubs.Reflection.Types.fv
let bool_fv = R.pack_fv bool_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 43, "start_col": 0, "start_line": 43 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.bool_lid" ]
[]
false
false
false
true
false
let bool_fv =
R.pack_fv bool_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.szt_tm
val szt_tm : FStar.Stubs.Reflection.Types.term
let szt_tm = R.pack_ln (R.Tv_FVar szt_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 50, "start_col": 0, "start_line": 50 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.szt_fv" ]
[]
false
false
false
true
false
let szt_tm =
R.pack_ln (R.Tv_FVar szt_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.nat_lid
val nat_lid : Prims.list Prims.string
let nat_lid = ["Prims"; "nat"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 45, "start_col": 0, "start_line": 45 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let nat_lid =
["Prims"; "nat"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.szv_fv
val szv_fv : FStar.Stubs.Reflection.Types.fv
let szv_fv = R.pack_fv szv_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 52, "start_col": 0, "start_line": 52 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.szv_lid" ]
[]
false
false
false
true
false
let szv_fv =
R.pack_fv szv_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.vprop_tm
val vprop_tm : FStar.Stubs.Reflection.Types.term
let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 40, "start_col": 0, "start_line": 40 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.vprop_fv" ]
[]
false
false
false
true
false
let vprop_tm =
R.pack_ln (R.Tv_FVar vprop_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.nat_fv
val nat_fv : FStar.Stubs.Reflection.Types.fv
let nat_fv = R.pack_fv nat_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 46, "start_col": 0, "start_line": 46 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.nat_lid" ]
[]
false
false
false
true
false
let nat_fv =
R.pack_fv nat_lid
false
MerkleTree.Low.fst
MerkleTree.Low.mt_flush_pre
val mt_flush_pre: mt:const_mt_p -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True))
val mt_flush_pre: mt:const_mt_p -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True))
let mt_flush_pre mt = mt_flush_pre_nst !*(CB.cast mt)
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 53, "end_line": 2500, "start_col": 0, "start_line": 2500 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after))))) #push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1" let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) #pop-options // For given a target index `k`, the number of elements (in the tree) `j`, // and a boolean flag (to check the existence of rightmost hashes), we can // calculate a required Merkle path length. // // `mt_path_length` is a postcondition of `mt_get_path`, and a precondition // of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`. private val mt_path_length_step: k:index_t -> j:index_t{k <= j} -> actd:bool -> Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd}) let mt_path_length_step k j actd = if j = 0ul then 0ul else (if k % 2ul = 0ul then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul) else 1ul) private inline_for_extraction val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j)) #push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1" let rec mt_path_length lv k j actd = if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd) #pop-options val mt_get_path_length: mtr:HH.rid -> p:const_path_p -> HST.ST uint32_t (requires (fun h0 -> path_safe h0 mtr (CB.cast p))) (ensures (fun h0 _ h1 -> True)) let mt_get_path_length mtr p = let pd = !*(CB.cast p) in V.size_of (Path?.hashes pd) private inline_for_extraction val mt_make_path_step: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\ V.size_of (phashes h1 p) <= lv + 2ul /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_make_path_step (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2" let mt_make_path_step #hsz lv mtr hs rhs i j k p actd = let pth = !*p in let hh0 = HST.get () in let ofs = offset_of i in if k % 2ul = 1ul then begin hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs)))); assert(Path?.hash_size pth = hsz); mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs)) end else begin if k = j then () else if k + 1ul = j then (if actd then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv))); mt_path_insert mtr p (V.index rhs lv))) else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs)))); mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs))) end #pop-options private inline_for_extraction val mt_get_path_step_pre_nst: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:path -> i:uint32_t -> Tot bool let mt_get_path_step_pre_nst #hsz mtr p i = i < V.size_of (Path?.hashes p) val mt_get_path_step_pre: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST bool (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ mt_get_path_step_pre_nst #hsz mtr pv i))) (ensures (fun _ _ _ -> True)) let mt_get_path_step_pre #hsz mtr p i = let p = CB.cast p in mt_get_path_step_pre_nst #hsz mtr !*p i val mt_get_path_step: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST (hash #hsz) (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ i < V.size_of (Path?.hashes pv)))) (ensures (fun h0 r h1 -> True )) let mt_get_path_step #hsz mtr p i = let pd = !*(CB.cast p) in V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i private val mt_get_path_: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length lv k j actd /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2" let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd = let hh0 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; let ofs = offset_of i in if j = 0ul then () else (mt_make_path_step lv mtr hs rhs i j k p actd; let hh1 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (lift_path hh1 mtr p) (MTH.mt_make_path_step (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd)); RV.rv_inv_preserved hs (path_loc p) hh0 hh1; RV.rv_inv_preserved rhs (path_loc p) hh0 hh1; RV.as_seq_preserved hs (path_loc p) hh0 hh1; RV.as_seq_preserved rhs (path_loc p) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1; assert (mt_safe_elts hh1 lv hs i j); mt_safe_elts_rec hh1 lv hs i j; mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p (if j % 2ul = 0ul then actd else true); let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv + 1) (RV.as_seq hh1 hs) (RV.as_seq hh1 rhs) (U32.v i / 2) (U32.v j / 2) (U32.v k / 2) (lift_path hh1 mtr p) (if U32.v j % 2 = 0 then actd else true))); assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd))) #pop-options private inline_for_extraction val mt_get_path_pre_nst: mtv:merkle_tree -> idx:offset_t -> p:path -> root:(hash #(MT?.hash_size mtv)) -> Tot bool let mt_get_path_pre_nst mtv idx p root = offsets_connect (MT?.offset mtv) idx && Path?.hash_size p = MT?.hash_size mtv && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in MT?.i mtv <= idx && idx < MT?.j mtv && V.size_of (Path?.hashes p) = 0ul) val mt_get_path_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:const_path_p -> root:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let dmt = B.get h0 mt 0 in let dp = B.get h0 p 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ Path?.hash_size dp = (Ghost.reveal hsz) /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun _ _ _ -> True)) let mt_get_path_pre #_ mt idx p root = let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_get_path_pre_nst mtv idx !*p root val mt_get_path_loc_union_helper: l1:loc -> l2:loc -> Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2) let mt_get_path_loc_union_helper l1 l2 = () // Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost // hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree // to the output path. #push-options "--z3rlimit 60" val mt_get_path: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:path_p -> root:hash #hsz -> HST.ST index_t (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let idx = split_offset (MT?.offset mtv0) idx in MT?.hash_size mtv0 = Ghost.reveal hsz /\ MT?.hash_size mtv1 = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\ // memory safety modifies (loc_union (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) h0 h1 /\ mt_safe h1 mt /\ path_safe h1 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h1 root /\ V.size_of (phashes h1 p) == 1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\ // correctness (let sj, sp, srt = MTH.mt_get_path (mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in sj == U32.v (MT?.j mtv1) /\ S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\ srt == Rgl?.r_repr (hreg hsz) h1 root))) #pop-options #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" let mt_get_path #hsz mt idx p root = let ncmt = CB.cast mt in let mtframe = B.frameOf ncmt in let hh0 = HST.get () in mt_get_root mt root; let mtv = !*ncmt in let hsz = MT?.hash_size mtv in let hh1 = HST.get () in path_safe_init_preserved mtframe p (B.loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) hh0 hh1; assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) == (mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root)); assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty); let idx = split_offset (MT?.offset mtv) idx in let i = MT?.i mtv in let ofs = offset_of (MT?.i mtv) in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in assert (mt_safe_elts hh1 0ul hs i j); assert (V.size_of (V.get hh1 hs 0ul) == j - ofs); assert (idx < j); hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs); hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs); hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs); let ih = V.index (V.index hs 0ul) (idx - ofs) in mt_path_insert #hsz mtframe p ih; let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtframe p) (MTH.path_insert (lift_path hh1 mtframe p) (S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs)))); Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2; mt_safe_preserved ncmt (path_loc p) hh1 hh2; mt_preserved ncmt (path_loc p) hh1 hh2; assert (V.size_of (phashes hh2 p) == 1ul); mt_get_path_ 0ul mtframe hs rhs i j idx p false; let hh3 = HST.get () in // memory safety mt_get_path_loc_union_helper (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p); Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3; mt_safe_preserved ncmt (path_loc p) hh2 hh3; mt_preserved ncmt (path_loc p) hh2 hh3; assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); assert (S.length (lift_path #hsz hh3 mtframe p) == S.length (lift_path #hsz hh2 mtframe p) + MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false); assert (modifies (loc_union (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) hh0 hh3); assert (mt_safe hh3 ncmt); assert (path_safe hh3 mtframe p); assert (Rgl?.r_inv (hreg hsz) hh3 root); assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); // correctness mt_safe_elts_spec hh2 0ul hs i j; assert (S.equal (lift_path hh3 mtframe p) (MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs) (U32.v i) (U32.v j) (U32.v idx) (lift_path hh2 mtframe p) false)); assert (MTH.mt_get_path (mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) == (U32.v (MT?.j (B.get hh3 ncmt 0)), lift_path hh3 mtframe p, Rgl?.r_repr (hreg hsz) hh3 root)); j #pop-options /// Flushing private val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) #push-options "--initial_fuel 2 --max_fuel 2" let mt_flush_to_modifies_rec_helper #hsz lv hs h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val mt_flush_to_: hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> pi:index_t -> i:index_t{i >= pi} -> j:Ghost.erased index_t{ Ghost.reveal j >= i && U32.v (Ghost.reveal j) < pow2 (32 - U32.v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs pi (Ghost.reveal j))) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1 /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i (Ghost.reveal j) /\ // correctness (mt_safe_elts_spec h0 lv hs pi (Ghost.reveal j); S.equal (RV.as_seq h1 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq h0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))))) (decreases (U32.v i)) #restart-solver #push-options "--z3rlimit 1500 --fuel 1 --ifuel 0" let rec mt_flush_to_ hsz lv hs pi i j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs pi (Ghost.reveal j); V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); let oi = offset_of i in let opi = offset_of pi in if oi = opi then mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j) else begin /// 1) Flush hashes at the level `lv`, where the new vector is /// not yet connected to `hs`. let ofs = oi - opi in let hvec = V.index hs lv in let flushed:(rvector (hreg hsz)) = rv_flush_inplace hvec ofs in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) flushed); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of flushed == Ghost.reveal j - offset_of i); // head updated mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 flushed) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) (U32.v ofs) (S.length (RV.as_seq hh0 (V.get hh0 hs lv))))); /// 2) Assign the flushed vector to `hs` at the level `lv`. RV.assign hs lv flushed; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == Ghost.reveal j - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector flushed) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector flushed) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 flushed) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 flushed); // if `lv = 31` then `pi <= i <= j < 2` thus `oi = opi`, // contradicting the branch. assert (lv + 1ul < merkle_tree_size_lg); assert (U32.v (Ghost.reveal j / 2ul) < pow2 (32 - U32.v (lv + 1ul))); assert (RV.rv_inv hh2 hs); assert (mt_safe_elts hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)); /// 3) Recursion mt_flush_to_ hsz (lv + 1ul) hs (pi / 2ul) (i / 2ul) (Ghost.hide (Ghost.reveal j / 2ul)); let hh3 = HST.get () in // 3-0) Memory safety brought from the postcondition of the recursion assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == Ghost.reveal j - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i (Ghost.reveal j); assert (mt_safe_elts hh3 lv hs i (Ghost.reveal j)); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv + 1) (RV.as_seq hh2 hs) (U32.v pi / 2) (U32.v i / 2) (U32.v (Ghost.reveal j) / 2))); mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j); MTH.mt_flush_to_rec (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))) end #pop-options // `mt_flush_to` flushes old hashes in the Merkle tree. It removes hash elements // from `MT?.i` to **`offset_of (idx - 1)`**, but maintains the tree structure, // i.e., the tree still holds some old internal hashes (compressed from old // hashes) which are required to generate Merkle paths for remaining hashes. // // Note that `mt_flush_to` (and `mt_flush`) always remain at least one base hash // elements. If there are `MT?.j` number of elements in the tree, because of the // precondition `MT?.i <= idx < MT?.j` we still have `idx`-th element after // flushing. private inline_for_extraction val mt_flush_to_pre_nst: mtv:merkle_tree -> idx:offset_t -> Tot bool let mt_flush_to_pre_nst mtv idx = offsets_connect (MT?.offset mtv) idx && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in idx >= MT?.i mtv && idx < MT?.j mtv) val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_flush_to_pre mt idx = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_flush_to_pre_nst mtv idx #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" val mt_flush_to: mt:mt_p -> idx:offset_t -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx)) (ensures (fun h0 _ h1 -> // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let off = MT?.offset mtv0 in let idx = split_offset off idx in MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_flush_to (mt_lift h0 mt) (U32.v idx) == mt_lift h1 mt))) let mt_flush_to mt idx = let hh0 = HST.get () in let mtv = !*mt in let offset = MT?.offset mtv in let j = MT?.j mtv in let hsz = MT?.hash_size mtv in let idx = split_offset offset idx in let hs = MT?.hs mtv in mt_flush_to_ hsz 0ul hs (MT?.i mtv) idx (Ghost.hide (MT?.j mtv)); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) idx (MT?.j mtv) hs (MT?.rhs_ok mtv) (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul hs idx (MT?.j mtv) (B.loc_buffer mt) hh1 hh2 #pop-options private inline_for_extraction val mt_flush_pre_nst: mt:merkle_tree -> Tot bool let mt_flush_pre_nst mt = MT?.j mt > MT?.i mt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.const_mt_p -> FStar.HyperStack.ST.ST Prims.bool
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.const_mt_p", "MerkleTree.Low.mt_flush_pre_nst", "Prims.bool", "MerkleTree.Low.merkle_tree", "LowStar.BufferOps.op_Bang_Star", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.ConstBuffer.cast" ]
[]
false
true
false
false
false
let mt_flush_pre mt =
mt_flush_pre_nst !*(CB.cast mt)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.nat_tm
val nat_tm : FStar.Stubs.Reflection.Types.term
let nat_tm = R.pack_ln (R.Tv_FVar nat_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 47, "start_col": 0, "start_line": 47 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.nat_fv" ]
[]
false
false
false
true
false
let nat_tm =
R.pack_ln (R.Tv_FVar nat_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.szt_fv
val szt_fv : FStar.Stubs.Reflection.Types.fv
let szt_fv = R.pack_fv szt_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 49, "start_col": 0, "start_line": 49 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.szt_lid" ]
[]
false
false
false
true
false
let szt_fv =
R.pack_fv szt_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.seq_lid
val seq_lid : Prims.list Prims.string
let seq_lid = ["FStar"; "Seq"; "Base"; "seq"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 54, "start_col": 0, "start_line": 54 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let seq_lid =
["FStar"; "Seq"; "Base"; "seq"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.szt_lid
val szt_lid : Prims.list Prims.string
let szt_lid = ["FStar"; "SizeT"; "t"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 48, "start_col": 0, "start_line": 48 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let szt_lid =
["FStar"; "SizeT"; "t"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.szv_lid
val szv_lid : Prims.list Prims.string
let szv_lid = ["FStar"; "SizeT"; "v"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 51, "start_col": 0, "start_line": 51 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let szv_lid =
["FStar"; "SizeT"; "v"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.szv_tm
val szv_tm : FStar.Stubs.Reflection.Types.term
let szv_tm = R.pack_ln (R.Tv_FVar szv_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 53, "start_col": 0, "start_line": 53 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.szv_fv" ]
[]
false
false
false
true
false
let szv_tm =
R.pack_ln (R.Tv_FVar szv_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.seq_create_lid
val seq_create_lid : Prims.list Prims.string
let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 55, "start_col": 0, "start_line": 55 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let seq_create_lid =
["FStar"; "Seq"; "Base"; "create"]
false
MerkleTree.Low.fst
MerkleTree.Low.mt_insert
val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v)))
val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v)))
let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 11, "end_line": 1018, "start_col": 0, "start_line": 964 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: FStar.Ghost.erased MerkleTree.Low.Datastructures.hash_size_t -> mt: MerkleTree.Low.mt_p -> v: MerkleTree.Low.Datastructures.hash -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.mt_p", "MerkleTree.Low.Datastructures.hash", "FStar.Ghost.reveal", "MerkleTree.Low.mt_safe_elts_preserved", "MerkleTree.Low.__proj__MT__item__hash_size", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.__proj__MT__item__hs", "MerkleTree.Low.__proj__MT__item__i", "FStar.Integers.op_Plus", "FStar.Integers.Unsigned", "FStar.Integers.W32", "MerkleTree.Low.__proj__MT__item__j", "LowStar.Monotonic.Buffer.loc_buffer", "MerkleTree.Low.merkle_tree", "LowStar.Buffer.trivial_preorder", "Prims.unit", "LowStar.Regional.__proj__Rgl__item__r_sep", "MerkleTree.Low.Datastructures.hreg", "MerkleTree.Low.__proj__MT__item__mroot", "LowStar.RVector.as_seq_preserved", "MerkleTree.Low.__proj__MT__item__rhs", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Datastructures.hvreg", "LowStar.RVector.rv_inv_preserved", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.BufferOps.op_Star_Equals", "MerkleTree.Low.MT", "MerkleTree.Low.__proj__MT__item__offset", "MerkleTree.Low.__proj__MT__item__hash_spec", "MerkleTree.Low.__proj__MT__item__hash_fun", "LowStar.Monotonic.Buffer.loc_union", "LowStar.RVector.rv_loc_elems", "LowStar.Vector.size_of", "LowStar.Vector.loc_vector_within", "LowStar.Monotonic.Buffer.loc_all_regions_from", "LowStar.Monotonic.Buffer.frameOf", "Lib.IntTypes.uint8", "LowStar.Vector.loc_vector_within_included", "LowStar.RVector.rv_loc_elems_included", "MerkleTree.Low.insert_", "FStar.Ghost.hide", "MerkleTree.Low.index_t", "MerkleTree.Low.Datastructures.hash_vv", "Prims.b2t", "Prims.op_Equality", "LowStar.Vector.uint32_t", "MerkleTree.Low.merkle_tree_size_lg", "LowStar.BufferOps.op_Bang_Star" ]
[]
false
true
false
false
false
let mt_insert hsz mt v =
let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.tot_lid
val tot_lid : Prims.list Prims.string
let tot_lid = ["Prims"; "Tot"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 56, "start_col": 0, "start_line": 56 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let tot_lid =
["Prims"; "Tot"]
false
Test.NoHeap.fst
Test.NoHeap.test_one_hkdf
val test_one_hkdf: hkdf_vector -> Stack unit (fun _ -> True) (fun _ _ _ -> True)
val test_one_hkdf: hkdf_vector -> Stack unit (fun _ -> True) (fun _ _ _ -> True)
let test_one_hkdf vec = let ha, (LB ikmlen ikm), (LB saltlen salt), (LB infolen info), (LB prklen expected_prk), (LB okmlen expected_okm) = vec in if Spec.Hash.Definitions.is_shake ha then failwith "unsupported shake algorithm" else if prklen <> Hacl.Hash.Definitions.hash_len ha then failwith "Wrong length of expected PRK\n" else if okmlen > 255ul * Hacl.Hash.Definitions.hash_len ha then failwith "Wrong output length\n" else if not (keysized ha saltlen) then failwith "Saltlen is not keysized\n" else if not (keysized ha prklen) then failwith "Prklen is not keysized\n" else if not (ikmlen <= 0xfffffffful - Hacl.Hash.Definitions.block_len ha) then failwith "ikmlen is too large\n" else if not (infolen <= 0xfffffffful - Hacl.Hash.Definitions.(block_len ha + hash_len ha + 1ul)) then failwith "infolen is too large\n" else if EverCrypt.HMAC.is_supported_alg ha then begin push_frame(); assert (Spec.Agile.HMAC.keysized ha (v saltlen)); assert (v ikmlen + Spec.Hash.Definitions.block_length ha < pow2 32); assert Spec.Hash.Definitions.(hash_length ha + v infolen + 1 + block_length ha < pow2 32); B.recall salt; B.recall ikm; B.recall info; let str = string_of_alg ha in let computed_prk = B.alloca 0uy (Hacl.Hash.Definitions.hash_len ha) in EverCrypt.HKDF.extract ha computed_prk salt saltlen ikm ikmlen; B.recall expected_prk; TestLib.compare_and_print str expected_prk computed_prk (Hacl.Hash.Definitions.hash_len ha); let computed_okm = B.alloca 0uy (okmlen + 1ul) in let computed_okm = B.sub computed_okm 0ul okmlen in EverCrypt.HKDF.expand ha computed_okm computed_prk prklen info infolen okmlen; B.recall expected_okm; TestLib.compare_and_print str expected_okm computed_okm okmlen; pop_frame() end
{ "file_name": "providers/test/Test.NoHeap.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 176, "start_col": 0, "start_line": 137 }
module Test.NoHeap module B = LowStar.Buffer module L = Test.Lowstarize module U32 = FStar.UInt32 open FStar.HyperStack.ST open FStar.Integers open LowStar.BufferOps open Test.Lowstarize let string_of_alg: Spec.Agile.Hash.hash_alg -> C.String.t = let open C.String in let open Spec.Agile.Hash in function | MD5 -> !$"MD5" | SHA1 -> !$"SHA1" | SHA2_224 -> !$"SHA2_224" | SHA2_256 -> !$"SHA2_256" | SHA2_384 -> !$"SHA2_384" | SHA2_512 -> !$"SHA2_512" | SHA3_224 -> !$"SHA3_224" | SHA3_256 -> !$"SHA3_256" | SHA3_384 -> !$"SHA3_384" | SHA3_512 -> !$"SHA3_512" | Blake2S -> !$"Blake2S" | Blake2B -> !$"Blake2B" | Shake128 -> !$"Shake128" | Shake256 -> !$"Shake256" /// A module that contains stack-only tests, suitable for both C and Wasm. Other /// tests that may make arbitrary use of the heap are in Test and Test.Hash. /// /// .. note:: /// Tests in this module are *VERIFIED*. Please keep it this way. noextract unfold inline_for_extraction let (!$) = C.String.((!$)) noextract unfold inline_for_extraction let failwith = LowStar.Failure.failwith /// Using meta-evaluated Low* test vectors from Test.Vectors /// ======================================================== /// /// Hashes /// ------ #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300" val test_one_hash: hash_vector -> Stack unit (fun _ -> true) (fun _ _ _ -> true) let test_one_hash vec = let a, input, (LB expected_len expected), repeat = vec in if Spec.Hash.Definitions.is_shake a then failwith "unsupported shake algorithm" else let input_len = C.String.strlen input in let tlen = Hacl.Hash.Definitions.hash_len a in if expected_len <> tlen then failwith "Wrong length of expected tag\n" else if repeat = 0ul then failwith "Repeat must be non-zero\n" else if not (input_len <= (0xfffffffful - 1ul) / repeat) then failwith "Repeated input is too large\n" else begin push_frame(); let computed = B.alloca 0uy tlen in assert_norm (v 0xfffffffful = pow2 32 - 1); assert (v input_len * v repeat + 1 < pow2 32); let total_input_len = input_len * repeat in let total_input = B.alloca 0uy (total_input_len + 1ul) in let total_input = B.sub total_input 0ul total_input_len in let h0 = get () in C.Loops.for 0ul repeat (fun h i -> B.live h total_input /\ B.modifies (B.loc_buffer total_input) h0 h) (fun i -> assert (v input_len * v i + v input_len <= v input_len * (v repeat - 1) + v input_len); assert (v input_len * v i + v input_len <= v input_len * v repeat); C.String.memcpy (B.sub total_input (input_len * i) input_len) input input_len ); EverCrypt.Hash.uint32_fits_maxLength a total_input_len; assert (v total_input_len `Spec.Hash.Definitions.less_than_max_input_length` a); EverCrypt.Hash.Incremental.hash a computed total_input total_input_len; B.recall expected; let str = string_of_alg a in TestLib.compare_and_print str expected computed tlen; pop_frame() end let test_hash = test_many !$"Hashes" test_one_hash /// HMAC /// ---- let keysized (a:H.alg) (l: UInt32.t): Tot (b:bool{b ==> Spec.Agile.HMAC.keysized a (UInt32.v l) }) = EverCrypt.Hash.uint32_fits_maxLength a l; assert (v l `Spec.Hash.Definitions.less_than_max_input_length` a); assert_norm (v 0xfffffffful = pow2 32 - 1); l <= 0xfffffffful - Hacl.Hash.Definitions.block_len a val test_one_hmac: hmac_vector -> Stack unit (fun _ -> True) (fun _ _ _ -> True) let test_one_hmac vec = let ha, (LB keylen key), (LB datalen data), (LB expectedlen expected) = vec in if Spec.Hash.Definitions.is_shake ha then failwith "unsupported shake algorithm" else if expectedlen <> Hacl.Hash.Definitions.hash_len ha then failwith "Wrong length of expected tag\n" else if not (keysized ha keylen) then failwith "Keysized predicate not satisfied\n" else if not (datalen <= 0xfffffffful - Hacl.Hash.Definitions.block_len ha) then failwith "Datalen predicate not satisfied\n" else if EverCrypt.HMAC.is_supported_alg ha then begin push_frame(); assert (Spec.Agile.HMAC.keysized ha (v keylen)); assert (v datalen + Spec.Hash.Definitions.block_length ha < pow2 32); B.recall key; B.recall data; let computed = B.alloca 0uy (Hacl.Hash.Definitions.hash_len ha) in EverCrypt.HMAC.compute ha computed key keylen data datalen; let str = string_of_alg ha in B.recall expected; TestLib.compare_and_print str expected computed (Hacl.Hash.Definitions.hash_len ha); pop_frame() end let test_hmac = test_many !$"HMAC" test_one_hmac /// HKDF /// ----
{ "checked_file": "/", "dependencies": [ "TestLib.fsti.checked", "Test.Vectors.Poly1305.fst.checked", "Test.Vectors.Curve25519.fst.checked", "Test.Vectors.Chacha20Poly1305.fst.checked", "Test.Vectors.fst.checked", "Test.Lowstarize.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Failure.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "EverCrypt.Poly1305.fsti.checked", "EverCrypt.HMAC.fsti.checked", "EverCrypt.HKDF.fsti.checked", "EverCrypt.Hash.Incremental.fst.checked", "EverCrypt.Hash.fsti.checked", "EverCrypt.Curve25519.fsti.checked", "EverCrypt.Cipher.fsti.checked", "EverCrypt.Chacha20Poly1305.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "Test.NoHeap.fst" }
[ { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "H" }, { "abbrev": false, "full_module": "Test", "short_module": null }, { "abbrev": false, "full_module": "Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vec: Test.NoHeap.hkdf_vector -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Test.NoHeap.hkdf_vector", "Spec.Hash.Definitions.hash_alg", "FStar.UInt32.t", "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.l_and", "Prims.eq2", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.recallable", "Spec.Hash.Definitions.is_shake", "Test.NoHeap.failwith", "Prims.unit", "Prims.bool", "Prims.op_disEquality", "Hacl.Hash.Definitions.hash_len", "FStar.Integers.op_Greater", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.op_Star", "FStar.UInt32.__uint_to_t", "Prims.op_Negation", "Test.NoHeap.keysized", "FStar.Integers.op_Less_Equals", "FStar.Integers.op_Subtraction", "Hacl.Hash.Definitions.block_len", "FStar.Integers.op_Plus", "EverCrypt.HMAC.is_supported_alg", "FStar.HyperStack.ST.pop_frame", "TestLib.compare_and_print", "LowStar.Monotonic.Buffer.recall", "EverCrypt.HKDF.expand", "LowStar.Monotonic.Buffer.mbuffer", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "LowStar.Buffer.sub", "Lib.IntTypes.uint8", "FStar.Ghost.hide", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.b2t", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.UInt8.__uint_to_t", "EverCrypt.HKDF.extract", "C.String.t", "Test.NoHeap.string_of_alg", "Prims._assert", "FStar.Integers.op_Less", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "Spec.Hash.Definitions.hash_length", "FStar.Integers.v", "Spec.Hash.Definitions.block_length", "Prims.pow2", "Spec.Agile.HMAC.keysized", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let test_one_hkdf vec =
let ha, LB ikmlen ikm, LB saltlen salt, LB infolen info, LB prklen expected_prk, LB okmlen expected_okm = vec in if Spec.Hash.Definitions.is_shake ha then failwith "unsupported shake algorithm" else if prklen <> Hacl.Hash.Definitions.hash_len ha then failwith "Wrong length of expected PRK\n" else if okmlen > 255ul * Hacl.Hash.Definitions.hash_len ha then failwith "Wrong output length\n" else if not (keysized ha saltlen) then failwith "Saltlen is not keysized\n" else if not (keysized ha prklen) then failwith "Prklen is not keysized\n" else if not (ikmlen <= 0xfffffffful - Hacl.Hash.Definitions.block_len ha) then failwith "ikmlen is too large\n" else if not (infolen <= 0xfffffffful - Hacl.Hash.Definitions.(block_len ha + hash_len ha + 1ul)) then failwith "infolen is too large\n" else if EverCrypt.HMAC.is_supported_alg ha then (push_frame (); assert (Spec.Agile.HMAC.keysized ha (v saltlen)); assert (v ikmlen + Spec.Hash.Definitions.block_length ha < pow2 32); assert Spec.Hash.Definitions.(hash_length ha + v infolen + 1 + block_length ha < pow2 32); B.recall salt; B.recall ikm; B.recall info; let str = string_of_alg ha in let computed_prk = B.alloca 0uy (Hacl.Hash.Definitions.hash_len ha) in EverCrypt.HKDF.extract ha computed_prk salt saltlen ikm ikmlen; B.recall expected_prk; TestLib.compare_and_print str expected_prk computed_prk (Hacl.Hash.Definitions.hash_len ha); let computed_okm = B.alloca 0uy (okmlen + 1ul) in let computed_okm = B.sub computed_okm 0ul okmlen in EverCrypt.HKDF.expand ha computed_okm computed_prk prklen info infolen okmlen; B.recall expected_okm; TestLib.compare_and_print str expected_okm computed_okm okmlen; pop_frame ())
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.tuple2_lid
val tuple2_lid : Prims.list Prims.string
let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 60, "end_line": 63, "start_col": 0, "start_line": 63 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let tuple2_lid =
["FStar"; "Pervasives"; "Native"; "tuple2"]
false
Test.NoHeap.fst
Test.NoHeap.test_one_chacha20
val test_one_chacha20 (v: chacha20_vector) : Stack unit (fun _ -> True) (fun _ _ _ -> True)
val test_one_chacha20 (v: chacha20_vector) : Stack unit (fun _ -> True) (fun _ _ _ -> True)
let test_one_chacha20 (v: chacha20_vector): Stack unit (fun _ -> True) (fun _ _ _ -> True) = let (LB key_len key), (LB iv_len iv), ctr, (LB plain_len plain), (LB cipher_len cipher) = v in if cipher_len = 0xfffffffful then failwith "Cipher too long" else if cipher_len <> plain_len then failwith "Cipher len and plain len don't match" else if key_len <> 32ul then failwith "invalid key len" else if iv_len <> 12ul then failwith "invalid iv len" else if not (ctr <= 0xfffffffful - cipher_len / 64ul) then failwith "invalid len" else begin push_frame (); B.recall key; B.recall iv; B.recall plain; B.recall cipher; let cipher' = B.alloca 0uy (cipher_len + 1ul) in let cipher' = B.sub cipher' 0ul cipher_len in EverCrypt.Cipher.chacha20 plain_len cipher' plain key iv ctr; TestLib.compare_and_print !$"of ChaCha20 message" cipher cipher' cipher_len; pop_frame () end
{ "file_name": "providers/test/Test.NoHeap.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 208, "start_col": 0, "start_line": 185 }
module Test.NoHeap module B = LowStar.Buffer module L = Test.Lowstarize module U32 = FStar.UInt32 open FStar.HyperStack.ST open FStar.Integers open LowStar.BufferOps open Test.Lowstarize let string_of_alg: Spec.Agile.Hash.hash_alg -> C.String.t = let open C.String in let open Spec.Agile.Hash in function | MD5 -> !$"MD5" | SHA1 -> !$"SHA1" | SHA2_224 -> !$"SHA2_224" | SHA2_256 -> !$"SHA2_256" | SHA2_384 -> !$"SHA2_384" | SHA2_512 -> !$"SHA2_512" | SHA3_224 -> !$"SHA3_224" | SHA3_256 -> !$"SHA3_256" | SHA3_384 -> !$"SHA3_384" | SHA3_512 -> !$"SHA3_512" | Blake2S -> !$"Blake2S" | Blake2B -> !$"Blake2B" | Shake128 -> !$"Shake128" | Shake256 -> !$"Shake256" /// A module that contains stack-only tests, suitable for both C and Wasm. Other /// tests that may make arbitrary use of the heap are in Test and Test.Hash. /// /// .. note:: /// Tests in this module are *VERIFIED*. Please keep it this way. noextract unfold inline_for_extraction let (!$) = C.String.((!$)) noextract unfold inline_for_extraction let failwith = LowStar.Failure.failwith /// Using meta-evaluated Low* test vectors from Test.Vectors /// ======================================================== /// /// Hashes /// ------ #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300" val test_one_hash: hash_vector -> Stack unit (fun _ -> true) (fun _ _ _ -> true) let test_one_hash vec = let a, input, (LB expected_len expected), repeat = vec in if Spec.Hash.Definitions.is_shake a then failwith "unsupported shake algorithm" else let input_len = C.String.strlen input in let tlen = Hacl.Hash.Definitions.hash_len a in if expected_len <> tlen then failwith "Wrong length of expected tag\n" else if repeat = 0ul then failwith "Repeat must be non-zero\n" else if not (input_len <= (0xfffffffful - 1ul) / repeat) then failwith "Repeated input is too large\n" else begin push_frame(); let computed = B.alloca 0uy tlen in assert_norm (v 0xfffffffful = pow2 32 - 1); assert (v input_len * v repeat + 1 < pow2 32); let total_input_len = input_len * repeat in let total_input = B.alloca 0uy (total_input_len + 1ul) in let total_input = B.sub total_input 0ul total_input_len in let h0 = get () in C.Loops.for 0ul repeat (fun h i -> B.live h total_input /\ B.modifies (B.loc_buffer total_input) h0 h) (fun i -> assert (v input_len * v i + v input_len <= v input_len * (v repeat - 1) + v input_len); assert (v input_len * v i + v input_len <= v input_len * v repeat); C.String.memcpy (B.sub total_input (input_len * i) input_len) input input_len ); EverCrypt.Hash.uint32_fits_maxLength a total_input_len; assert (v total_input_len `Spec.Hash.Definitions.less_than_max_input_length` a); EverCrypt.Hash.Incremental.hash a computed total_input total_input_len; B.recall expected; let str = string_of_alg a in TestLib.compare_and_print str expected computed tlen; pop_frame() end let test_hash = test_many !$"Hashes" test_one_hash /// HMAC /// ---- let keysized (a:H.alg) (l: UInt32.t): Tot (b:bool{b ==> Spec.Agile.HMAC.keysized a (UInt32.v l) }) = EverCrypt.Hash.uint32_fits_maxLength a l; assert (v l `Spec.Hash.Definitions.less_than_max_input_length` a); assert_norm (v 0xfffffffful = pow2 32 - 1); l <= 0xfffffffful - Hacl.Hash.Definitions.block_len a val test_one_hmac: hmac_vector -> Stack unit (fun _ -> True) (fun _ _ _ -> True) let test_one_hmac vec = let ha, (LB keylen key), (LB datalen data), (LB expectedlen expected) = vec in if Spec.Hash.Definitions.is_shake ha then failwith "unsupported shake algorithm" else if expectedlen <> Hacl.Hash.Definitions.hash_len ha then failwith "Wrong length of expected tag\n" else if not (keysized ha keylen) then failwith "Keysized predicate not satisfied\n" else if not (datalen <= 0xfffffffful - Hacl.Hash.Definitions.block_len ha) then failwith "Datalen predicate not satisfied\n" else if EverCrypt.HMAC.is_supported_alg ha then begin push_frame(); assert (Spec.Agile.HMAC.keysized ha (v keylen)); assert (v datalen + Spec.Hash.Definitions.block_length ha < pow2 32); B.recall key; B.recall data; let computed = B.alloca 0uy (Hacl.Hash.Definitions.hash_len ha) in EverCrypt.HMAC.compute ha computed key keylen data datalen; let str = string_of_alg ha in B.recall expected; TestLib.compare_and_print str expected computed (Hacl.Hash.Definitions.hash_len ha); pop_frame() end let test_hmac = test_many !$"HMAC" test_one_hmac /// HKDF /// ---- val test_one_hkdf: hkdf_vector -> Stack unit (fun _ -> True) (fun _ _ _ -> True) let test_one_hkdf vec = let ha, (LB ikmlen ikm), (LB saltlen salt), (LB infolen info), (LB prklen expected_prk), (LB okmlen expected_okm) = vec in if Spec.Hash.Definitions.is_shake ha then failwith "unsupported shake algorithm" else if prklen <> Hacl.Hash.Definitions.hash_len ha then failwith "Wrong length of expected PRK\n" else if okmlen > 255ul * Hacl.Hash.Definitions.hash_len ha then failwith "Wrong output length\n" else if not (keysized ha saltlen) then failwith "Saltlen is not keysized\n" else if not (keysized ha prklen) then failwith "Prklen is not keysized\n" else if not (ikmlen <= 0xfffffffful - Hacl.Hash.Definitions.block_len ha) then failwith "ikmlen is too large\n" else if not (infolen <= 0xfffffffful - Hacl.Hash.Definitions.(block_len ha + hash_len ha + 1ul)) then failwith "infolen is too large\n" else if EverCrypt.HMAC.is_supported_alg ha then begin push_frame(); assert (Spec.Agile.HMAC.keysized ha (v saltlen)); assert (v ikmlen + Spec.Hash.Definitions.block_length ha < pow2 32); assert Spec.Hash.Definitions.(hash_length ha + v infolen + 1 + block_length ha < pow2 32); B.recall salt; B.recall ikm; B.recall info; let str = string_of_alg ha in let computed_prk = B.alloca 0uy (Hacl.Hash.Definitions.hash_len ha) in EverCrypt.HKDF.extract ha computed_prk salt saltlen ikm ikmlen; B.recall expected_prk; TestLib.compare_and_print str expected_prk computed_prk (Hacl.Hash.Definitions.hash_len ha); let computed_okm = B.alloca 0uy (okmlen + 1ul) in let computed_okm = B.sub computed_okm 0ul okmlen in EverCrypt.HKDF.expand ha computed_okm computed_prk prklen info infolen okmlen; B.recall expected_okm; TestLib.compare_and_print str expected_okm computed_okm okmlen; pop_frame() end let test_hkdf = test_many !$"HKDF" test_one_hkdf /// Chacha20 /// -------- friend Lib.IntTypes
{ "checked_file": "/", "dependencies": [ "TestLib.fsti.checked", "Test.Vectors.Poly1305.fst.checked", "Test.Vectors.Curve25519.fst.checked", "Test.Vectors.Chacha20Poly1305.fst.checked", "Test.Vectors.fst.checked", "Test.Lowstarize.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Failure.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "EverCrypt.Poly1305.fsti.checked", "EverCrypt.HMAC.fsti.checked", "EverCrypt.HKDF.fsti.checked", "EverCrypt.Hash.Incremental.fst.checked", "EverCrypt.Hash.fsti.checked", "EverCrypt.Curve25519.fsti.checked", "EverCrypt.Cipher.fsti.checked", "EverCrypt.Chacha20Poly1305.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "Test.NoHeap.fst" }
[ { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "H" }, { "abbrev": false, "full_module": "Test", "short_module": null }, { "abbrev": false, "full_module": "Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Test.NoHeap.chacha20_vector -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Test.NoHeap.chacha20_vector", "FStar.UInt32.t", "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.l_and", "Prims.eq2", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.recallable", "Prims.op_Equality", "FStar.UInt32.__uint_to_t", "Test.NoHeap.failwith", "Prims.unit", "Prims.bool", "Prims.op_disEquality", "Prims.op_Negation", "FStar.Integers.op_Less_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.op_Subtraction", "FStar.Integers.op_Slash", "FStar.HyperStack.ST.pop_frame", "TestLib.compare_and_print", "Test.NoHeap.op_Bang_Dollar", "EverCrypt.Cipher.chacha20", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.sub", "FStar.Ghost.hide", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.b2t", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.UInt8.__uint_to_t", "FStar.Integers.op_Plus", "LowStar.Monotonic.Buffer.recall", "FStar.HyperStack.ST.push_frame", "FStar.Monotonic.HyperStack.mem", "Prims.l_True" ]
[]
false
true
false
false
false
let test_one_chacha20 (v: chacha20_vector) : Stack unit (fun _ -> True) (fun _ _ _ -> True) =
let LB key_len key, LB iv_len iv, ctr, LB plain_len plain, LB cipher_len cipher = v in if cipher_len = 0xfffffffful then failwith "Cipher too long" else if cipher_len <> plain_len then failwith "Cipher len and plain len don't match" else if key_len <> 32ul then failwith "invalid key len" else if iv_len <> 12ul then failwith "invalid iv len" else if not (ctr <= 0xfffffffful - cipher_len / 64ul) then failwith "invalid len" else (push_frame (); B.recall key; B.recall iv; B.recall plain; B.recall cipher; let cipher' = B.alloca 0uy (cipher_len + 1ul) in let cipher' = B.sub cipher' 0ul cipher_len in EverCrypt.Cipher.chacha20 plain_len cipher' plain key iv ctr; TestLib.compare_and_print !$"of ChaCha20 message" cipher cipher' cipher_len; pop_frame ())
false
MerkleTree.Low.fst
MerkleTree.Low.mt_path_length
val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j))
val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j))
let rec mt_path_length lv k j actd = if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd)
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 59, "end_line": 1775, "start_col": 0, "start_line": 1771 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after))))) #push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1" let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) #pop-options // For given a target index `k`, the number of elements (in the tree) `j`, // and a boolean flag (to check the existence of rightmost hashes), we can // calculate a required Merkle path length. // // `mt_path_length` is a postcondition of `mt_get_path`, and a precondition // of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`. private val mt_path_length_step: k:index_t -> j:index_t{k <= j} -> actd:bool -> Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd}) let mt_path_length_step k j actd = if j = 0ul then 0ul else (if k % 2ul = 0ul then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul) else 1ul) private inline_for_extraction val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": 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": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: LowStar.Vector.uint32_t{lv <= MerkleTree.Low.merkle_tree_size_lg} -> k: MerkleTree.Low.index_t -> j: MerkleTree.Low.index_t{k <= j && FStar.UInt32.v j < Prims.pow2 (32 - FStar.UInt32.v lv)} -> actd: Prims.bool -> Prims.Tot (l: LowStar.Vector.uint32_t { FStar.UInt32.v l = MerkleTree.New.High.mt_path_length (FStar.UInt32.v k) (FStar.UInt32.v j) actd && l <= 32ul - lv })
Prims.Tot
[ "total", "" ]
[]
[ "LowStar.Vector.uint32_t", "Prims.b2t", "FStar.Integers.op_Less_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "MerkleTree.Low.merkle_tree_size_lg", "MerkleTree.Low.index_t", "Prims.op_AmpAmp", "FStar.Integers.op_Less", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.UInt32.v", "Prims.pow2", "FStar.Integers.op_Subtraction", "Prims.bool", "Prims.op_Equality", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "FStar.Integers.op_Plus", "MerkleTree.Low.mt_path_length_step", "MerkleTree.Low.mt_path_length", "FStar.Integers.op_Slash", "Prims.op_BarBar", "FStar.Integers.op_Percent", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "MerkleTree.New.High.mt_path_length" ]
[ "recursion" ]
false
false
false
false
false
let rec mt_path_length lv k j actd =
if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd)
false
MerkleTree.Low.fst
MerkleTree.Low.mt_retract_to_pre
val mt_retract_to_pre: mt:const_mt_p -> r:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True))
val mt_retract_to_pre: mt:const_mt_p -> r:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True))
let mt_retract_to_pre mt r = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_retract_to_pre_nst mtv r
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 29, "end_line": 2758, "start_col": 0, "start_line": 2754 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after))))) #push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1" let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) #pop-options // For given a target index `k`, the number of elements (in the tree) `j`, // and a boolean flag (to check the existence of rightmost hashes), we can // calculate a required Merkle path length. // // `mt_path_length` is a postcondition of `mt_get_path`, and a precondition // of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`. private val mt_path_length_step: k:index_t -> j:index_t{k <= j} -> actd:bool -> Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd}) let mt_path_length_step k j actd = if j = 0ul then 0ul else (if k % 2ul = 0ul then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul) else 1ul) private inline_for_extraction val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j)) #push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1" let rec mt_path_length lv k j actd = if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd) #pop-options val mt_get_path_length: mtr:HH.rid -> p:const_path_p -> HST.ST uint32_t (requires (fun h0 -> path_safe h0 mtr (CB.cast p))) (ensures (fun h0 _ h1 -> True)) let mt_get_path_length mtr p = let pd = !*(CB.cast p) in V.size_of (Path?.hashes pd) private inline_for_extraction val mt_make_path_step: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\ V.size_of (phashes h1 p) <= lv + 2ul /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_make_path_step (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2" let mt_make_path_step #hsz lv mtr hs rhs i j k p actd = let pth = !*p in let hh0 = HST.get () in let ofs = offset_of i in if k % 2ul = 1ul then begin hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs)))); assert(Path?.hash_size pth = hsz); mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs)) end else begin if k = j then () else if k + 1ul = j then (if actd then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv))); mt_path_insert mtr p (V.index rhs lv))) else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs)))); mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs))) end #pop-options private inline_for_extraction val mt_get_path_step_pre_nst: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:path -> i:uint32_t -> Tot bool let mt_get_path_step_pre_nst #hsz mtr p i = i < V.size_of (Path?.hashes p) val mt_get_path_step_pre: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST bool (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ mt_get_path_step_pre_nst #hsz mtr pv i))) (ensures (fun _ _ _ -> True)) let mt_get_path_step_pre #hsz mtr p i = let p = CB.cast p in mt_get_path_step_pre_nst #hsz mtr !*p i val mt_get_path_step: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST (hash #hsz) (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ i < V.size_of (Path?.hashes pv)))) (ensures (fun h0 r h1 -> True )) let mt_get_path_step #hsz mtr p i = let pd = !*(CB.cast p) in V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i private val mt_get_path_: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length lv k j actd /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2" let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd = let hh0 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; let ofs = offset_of i in if j = 0ul then () else (mt_make_path_step lv mtr hs rhs i j k p actd; let hh1 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (lift_path hh1 mtr p) (MTH.mt_make_path_step (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd)); RV.rv_inv_preserved hs (path_loc p) hh0 hh1; RV.rv_inv_preserved rhs (path_loc p) hh0 hh1; RV.as_seq_preserved hs (path_loc p) hh0 hh1; RV.as_seq_preserved rhs (path_loc p) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1; assert (mt_safe_elts hh1 lv hs i j); mt_safe_elts_rec hh1 lv hs i j; mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p (if j % 2ul = 0ul then actd else true); let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv + 1) (RV.as_seq hh1 hs) (RV.as_seq hh1 rhs) (U32.v i / 2) (U32.v j / 2) (U32.v k / 2) (lift_path hh1 mtr p) (if U32.v j % 2 = 0 then actd else true))); assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd))) #pop-options private inline_for_extraction val mt_get_path_pre_nst: mtv:merkle_tree -> idx:offset_t -> p:path -> root:(hash #(MT?.hash_size mtv)) -> Tot bool let mt_get_path_pre_nst mtv idx p root = offsets_connect (MT?.offset mtv) idx && Path?.hash_size p = MT?.hash_size mtv && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in MT?.i mtv <= idx && idx < MT?.j mtv && V.size_of (Path?.hashes p) = 0ul) val mt_get_path_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:const_path_p -> root:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let dmt = B.get h0 mt 0 in let dp = B.get h0 p 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ Path?.hash_size dp = (Ghost.reveal hsz) /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun _ _ _ -> True)) let mt_get_path_pre #_ mt idx p root = let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_get_path_pre_nst mtv idx !*p root val mt_get_path_loc_union_helper: l1:loc -> l2:loc -> Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2) let mt_get_path_loc_union_helper l1 l2 = () // Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost // hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree // to the output path. #push-options "--z3rlimit 60" val mt_get_path: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:path_p -> root:hash #hsz -> HST.ST index_t (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let idx = split_offset (MT?.offset mtv0) idx in MT?.hash_size mtv0 = Ghost.reveal hsz /\ MT?.hash_size mtv1 = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\ // memory safety modifies (loc_union (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) h0 h1 /\ mt_safe h1 mt /\ path_safe h1 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h1 root /\ V.size_of (phashes h1 p) == 1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\ // correctness (let sj, sp, srt = MTH.mt_get_path (mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in sj == U32.v (MT?.j mtv1) /\ S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\ srt == Rgl?.r_repr (hreg hsz) h1 root))) #pop-options #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" let mt_get_path #hsz mt idx p root = let ncmt = CB.cast mt in let mtframe = B.frameOf ncmt in let hh0 = HST.get () in mt_get_root mt root; let mtv = !*ncmt in let hsz = MT?.hash_size mtv in let hh1 = HST.get () in path_safe_init_preserved mtframe p (B.loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) hh0 hh1; assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) == (mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root)); assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty); let idx = split_offset (MT?.offset mtv) idx in let i = MT?.i mtv in let ofs = offset_of (MT?.i mtv) in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in assert (mt_safe_elts hh1 0ul hs i j); assert (V.size_of (V.get hh1 hs 0ul) == j - ofs); assert (idx < j); hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs); hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs); hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs); let ih = V.index (V.index hs 0ul) (idx - ofs) in mt_path_insert #hsz mtframe p ih; let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtframe p) (MTH.path_insert (lift_path hh1 mtframe p) (S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs)))); Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2; mt_safe_preserved ncmt (path_loc p) hh1 hh2; mt_preserved ncmt (path_loc p) hh1 hh2; assert (V.size_of (phashes hh2 p) == 1ul); mt_get_path_ 0ul mtframe hs rhs i j idx p false; let hh3 = HST.get () in // memory safety mt_get_path_loc_union_helper (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p); Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3; mt_safe_preserved ncmt (path_loc p) hh2 hh3; mt_preserved ncmt (path_loc p) hh2 hh3; assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); assert (S.length (lift_path #hsz hh3 mtframe p) == S.length (lift_path #hsz hh2 mtframe p) + MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false); assert (modifies (loc_union (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) hh0 hh3); assert (mt_safe hh3 ncmt); assert (path_safe hh3 mtframe p); assert (Rgl?.r_inv (hreg hsz) hh3 root); assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); // correctness mt_safe_elts_spec hh2 0ul hs i j; assert (S.equal (lift_path hh3 mtframe p) (MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs) (U32.v i) (U32.v j) (U32.v idx) (lift_path hh2 mtframe p) false)); assert (MTH.mt_get_path (mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) == (U32.v (MT?.j (B.get hh3 ncmt 0)), lift_path hh3 mtframe p, Rgl?.r_repr (hreg hsz) hh3 root)); j #pop-options /// Flushing private val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) #push-options "--initial_fuel 2 --max_fuel 2" let mt_flush_to_modifies_rec_helper #hsz lv hs h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val mt_flush_to_: hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> pi:index_t -> i:index_t{i >= pi} -> j:Ghost.erased index_t{ Ghost.reveal j >= i && U32.v (Ghost.reveal j) < pow2 (32 - U32.v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs pi (Ghost.reveal j))) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1 /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i (Ghost.reveal j) /\ // correctness (mt_safe_elts_spec h0 lv hs pi (Ghost.reveal j); S.equal (RV.as_seq h1 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq h0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))))) (decreases (U32.v i)) #restart-solver #push-options "--z3rlimit 1500 --fuel 1 --ifuel 0" let rec mt_flush_to_ hsz lv hs pi i j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs pi (Ghost.reveal j); V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); let oi = offset_of i in let opi = offset_of pi in if oi = opi then mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j) else begin /// 1) Flush hashes at the level `lv`, where the new vector is /// not yet connected to `hs`. let ofs = oi - opi in let hvec = V.index hs lv in let flushed:(rvector (hreg hsz)) = rv_flush_inplace hvec ofs in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) flushed); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of flushed == Ghost.reveal j - offset_of i); // head updated mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 flushed) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) (U32.v ofs) (S.length (RV.as_seq hh0 (V.get hh0 hs lv))))); /// 2) Assign the flushed vector to `hs` at the level `lv`. RV.assign hs lv flushed; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == Ghost.reveal j - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector flushed) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector flushed) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 flushed) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 flushed); // if `lv = 31` then `pi <= i <= j < 2` thus `oi = opi`, // contradicting the branch. assert (lv + 1ul < merkle_tree_size_lg); assert (U32.v (Ghost.reveal j / 2ul) < pow2 (32 - U32.v (lv + 1ul))); assert (RV.rv_inv hh2 hs); assert (mt_safe_elts hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)); /// 3) Recursion mt_flush_to_ hsz (lv + 1ul) hs (pi / 2ul) (i / 2ul) (Ghost.hide (Ghost.reveal j / 2ul)); let hh3 = HST.get () in // 3-0) Memory safety brought from the postcondition of the recursion assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == Ghost.reveal j - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i (Ghost.reveal j); assert (mt_safe_elts hh3 lv hs i (Ghost.reveal j)); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv + 1) (RV.as_seq hh2 hs) (U32.v pi / 2) (U32.v i / 2) (U32.v (Ghost.reveal j) / 2))); mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j); MTH.mt_flush_to_rec (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))) end #pop-options // `mt_flush_to` flushes old hashes in the Merkle tree. It removes hash elements // from `MT?.i` to **`offset_of (idx - 1)`**, but maintains the tree structure, // i.e., the tree still holds some old internal hashes (compressed from old // hashes) which are required to generate Merkle paths for remaining hashes. // // Note that `mt_flush_to` (and `mt_flush`) always remain at least one base hash // elements. If there are `MT?.j` number of elements in the tree, because of the // precondition `MT?.i <= idx < MT?.j` we still have `idx`-th element after // flushing. private inline_for_extraction val mt_flush_to_pre_nst: mtv:merkle_tree -> idx:offset_t -> Tot bool let mt_flush_to_pre_nst mtv idx = offsets_connect (MT?.offset mtv) idx && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in idx >= MT?.i mtv && idx < MT?.j mtv) val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_flush_to_pre mt idx = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_flush_to_pre_nst mtv idx #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" val mt_flush_to: mt:mt_p -> idx:offset_t -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx)) (ensures (fun h0 _ h1 -> // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let off = MT?.offset mtv0 in let idx = split_offset off idx in MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_flush_to (mt_lift h0 mt) (U32.v idx) == mt_lift h1 mt))) let mt_flush_to mt idx = let hh0 = HST.get () in let mtv = !*mt in let offset = MT?.offset mtv in let j = MT?.j mtv in let hsz = MT?.hash_size mtv in let idx = split_offset offset idx in let hs = MT?.hs mtv in mt_flush_to_ hsz 0ul hs (MT?.i mtv) idx (Ghost.hide (MT?.j mtv)); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) idx (MT?.j mtv) hs (MT?.rhs_ok mtv) (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul hs idx (MT?.j mtv) (B.loc_buffer mt) hh1 hh2 #pop-options private inline_for_extraction val mt_flush_pre_nst: mt:merkle_tree -> Tot bool let mt_flush_pre_nst mt = MT?.j mt > MT?.i mt val mt_flush_pre: mt:const_mt_p -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_flush_pre mt = mt_flush_pre_nst !*(CB.cast mt) val mt_flush: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_flush_pre_nst (B.get h0 mt 0))) (ensures (fun h0 _ h1 -> let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_flush (mt_lift h0 mt) == mt_lift h1 mt)) #push-options "--z3rlimit 200 --initial_fuel 1 --max_fuel 1" let mt_flush mt = let mtv = !*mt in let off = MT?.offset mtv in let j = MT?.j mtv in let j1 = j - 1ul in assert (j1 < uint32_32_max); assert (off < uint64_max); assert (UInt.fits (U64.v off + U32.v j1) 64); let jo = join_offset off j1 in mt_flush_to mt jo #pop-options /// Retraction private val mt_retract_to_: #hsz:hash_size_t -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> lv:uint32_t{lv < V.size_of hs} -> i:index_t -> s:index_t -> j:index_t{i <= s && s <= j && v j < pow2 (U32.v (V.size_of hs) - v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety (modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1) /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i s /\ // correctness (mt_safe_elts_spec h0 lv hs i j; S.equal (RV.as_seq h1 hs) (MTH.mt_retract_to_ (RV.as_seq h0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) )) (decreases (U32.v merkle_tree_size_lg - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" private let rec mt_retract_to_ #hsz hs lv i s j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs i j; V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); if lv >= V.size_of hs then () else begin // 1) Retract hashes at level `lv`. let hvec = V.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in let retracted = RV.shrink hvec new_len in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) retracted); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of retracted == new_len); mt_safe_elts_preserved (lv + 1ul) hs (i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 retracted) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) 0 (U32.v new_len))); RV.assign hs lv retracted; let hh2 = HST.get() in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == s - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector retracted) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector retracted) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 retracted) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 retracted); if lv + 1ul < V.size_of hs then begin assert (mt_safe_elts hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul)); mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_retract_to_ hs (lv + 1ul) (i / 2ul) (s / 2ul) (j / 2ul); // 3-0) Memory safety brought from the postcondition of the recursion let hh3 = HST.get () in assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == s - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i s; assert (mt_safe_elts hh3 lv hs i s); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (U32.v lv + 1 < S.length (RV.as_seq hh3 hs) ==> S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh2 hs) (U32.v lv + 1) (U32.v i / 2) (U32.v s / 2) (U32.v j / 2))); assert (RV.rv_inv hh0 hs); assert (mt_safe_elts hh0 lv hs i j); mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) end else begin let hh3 = HST.get() in assert ((modifies (loc_union (RV.rv_loc_elems hh0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) hh0 hh3)); assert (RV.rv_inv hh3 hs /\ mt_safe_elts hh3 lv hs i s); mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) end end #pop-options private inline_for_extraction val mt_retract_to_pre_nst: mtv:merkle_tree -> r:offset_t -> Tot bool let mt_retract_to_pre_nst mtv r = offsets_connect (MT?.offset mtv) r && ([@inline_let] let r = split_offset (MT?.offset mtv) r in MT?.i mtv <= r && r < MT?.j mtv) val mt_retract_to_pre: mt:const_mt_p -> r:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.const_mt_p -> r: MerkleTree.Low.offset_t -> FStar.HyperStack.ST.ST Prims.bool
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.const_mt_p", "MerkleTree.Low.offset_t", "MerkleTree.Low.mt_retract_to_pre_nst", "Prims.bool", "MerkleTree.Low.merkle_tree", "LowStar.BufferOps.op_Bang_Star", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.ConstBuffer.cast" ]
[]
false
true
false
false
false
let mt_retract_to_pre mt r =
let mt = CB.cast mt in let h0 = HST.get () in let mtv = !*mt in mt_retract_to_pre_nst mtv r
false
Test.NoHeap.fst
Test.NoHeap.test_one_chacha20poly1305
val test_one_chacha20poly1305 (v: Test.Vectors.Chacha20Poly1305.vector) : Stack unit (fun _ -> True) (fun _ _ _ -> True)
val test_one_chacha20poly1305 (v: Test.Vectors.Chacha20Poly1305.vector) : Stack unit (fun _ -> True) (fun _ _ _ -> True)
let test_one_chacha20poly1305 (v: Test.Vectors.Chacha20Poly1305.vector): Stack unit (fun _ -> True) (fun _ _ _ -> True) = let Test.Vectors.Chacha20Poly1305.Vector cipher_and_tag cipher_and_tag_len plain plain_len aad aad_len nonce nonce_len key key_len = v in if not (key_len = 32ul) then failwith "chacha20poly1305: not (key_len = 32ul)" else if not (nonce_len = 12ul) then failwith "chacha20poly1305: not (nonce_len = 12ul)" else if not ((4294967295ul `U32.sub` 16ul) `U32.gte` plain_len) then failwith "chacha20poly1305: not ((4294967295ul `U32.sub` 16ul) `U32.gte` plain_len)" else if not ((plain_len `U32.div` 64ul) `U32.lte` (4294967295ul `U32.sub` aad_len)) then failwith "chacha20poly1305: not ((plain_len `U32.div` 64ul) `U32.lte` (4294967295ul `U32.sub` aad_len))" else if not (cipher_and_tag_len = plain_len `U32.add` 16ul) then failwith "chacha20poly1305: not (cipher_and_tag_len = plain_len `U32.add` 16ul)" else begin B.recall plain; B.recall cipher_and_tag; B.recall aad; B.recall nonce; B.recall key; push_frame (); let tmp = B.alloca 0uy (plain_len `U32.add` 16ul) in let tmp_msg' = B.sub tmp 0ul plain_len in let tag' = B.sub tmp plain_len 16ul in EverCrypt.Chacha20Poly1305.aead_encrypt key nonce aad_len aad plain_len plain tmp_msg' tag'; TestLib.compare_and_print !$"chacha20poly1305 cipher and tag" cipher_and_tag tmp cipher_and_tag_len; let cipher = B.sub cipher_and_tag 0ul plain_len in let tag = B.sub cipher_and_tag plain_len 16ul in let res = EverCrypt.Chacha20Poly1305.aead_decrypt key nonce aad_len aad plain_len tmp_msg' cipher tag in if res = 0ul then TestLib.compare_and_print !$"chacha20poly1305 plain" plain tmp_msg' plain_len else failwith "Failure: chacha20poly1305 aead_decrypt returned nonzero value"; pop_frame () end
{ "file_name": "providers/test/Test.NoHeap.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 310, "start_col": 0, "start_line": 277 }
module Test.NoHeap module B = LowStar.Buffer module L = Test.Lowstarize module U32 = FStar.UInt32 open FStar.HyperStack.ST open FStar.Integers open LowStar.BufferOps open Test.Lowstarize let string_of_alg: Spec.Agile.Hash.hash_alg -> C.String.t = let open C.String in let open Spec.Agile.Hash in function | MD5 -> !$"MD5" | SHA1 -> !$"SHA1" | SHA2_224 -> !$"SHA2_224" | SHA2_256 -> !$"SHA2_256" | SHA2_384 -> !$"SHA2_384" | SHA2_512 -> !$"SHA2_512" | SHA3_224 -> !$"SHA3_224" | SHA3_256 -> !$"SHA3_256" | SHA3_384 -> !$"SHA3_384" | SHA3_512 -> !$"SHA3_512" | Blake2S -> !$"Blake2S" | Blake2B -> !$"Blake2B" | Shake128 -> !$"Shake128" | Shake256 -> !$"Shake256" /// A module that contains stack-only tests, suitable for both C and Wasm. Other /// tests that may make arbitrary use of the heap are in Test and Test.Hash. /// /// .. note:: /// Tests in this module are *VERIFIED*. Please keep it this way. noextract unfold inline_for_extraction let (!$) = C.String.((!$)) noextract unfold inline_for_extraction let failwith = LowStar.Failure.failwith /// Using meta-evaluated Low* test vectors from Test.Vectors /// ======================================================== /// /// Hashes /// ------ #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300" val test_one_hash: hash_vector -> Stack unit (fun _ -> true) (fun _ _ _ -> true) let test_one_hash vec = let a, input, (LB expected_len expected), repeat = vec in if Spec.Hash.Definitions.is_shake a then failwith "unsupported shake algorithm" else let input_len = C.String.strlen input in let tlen = Hacl.Hash.Definitions.hash_len a in if expected_len <> tlen then failwith "Wrong length of expected tag\n" else if repeat = 0ul then failwith "Repeat must be non-zero\n" else if not (input_len <= (0xfffffffful - 1ul) / repeat) then failwith "Repeated input is too large\n" else begin push_frame(); let computed = B.alloca 0uy tlen in assert_norm (v 0xfffffffful = pow2 32 - 1); assert (v input_len * v repeat + 1 < pow2 32); let total_input_len = input_len * repeat in let total_input = B.alloca 0uy (total_input_len + 1ul) in let total_input = B.sub total_input 0ul total_input_len in let h0 = get () in C.Loops.for 0ul repeat (fun h i -> B.live h total_input /\ B.modifies (B.loc_buffer total_input) h0 h) (fun i -> assert (v input_len * v i + v input_len <= v input_len * (v repeat - 1) + v input_len); assert (v input_len * v i + v input_len <= v input_len * v repeat); C.String.memcpy (B.sub total_input (input_len * i) input_len) input input_len ); EverCrypt.Hash.uint32_fits_maxLength a total_input_len; assert (v total_input_len `Spec.Hash.Definitions.less_than_max_input_length` a); EverCrypt.Hash.Incremental.hash a computed total_input total_input_len; B.recall expected; let str = string_of_alg a in TestLib.compare_and_print str expected computed tlen; pop_frame() end let test_hash = test_many !$"Hashes" test_one_hash /// HMAC /// ---- let keysized (a:H.alg) (l: UInt32.t): Tot (b:bool{b ==> Spec.Agile.HMAC.keysized a (UInt32.v l) }) = EverCrypt.Hash.uint32_fits_maxLength a l; assert (v l `Spec.Hash.Definitions.less_than_max_input_length` a); assert_norm (v 0xfffffffful = pow2 32 - 1); l <= 0xfffffffful - Hacl.Hash.Definitions.block_len a val test_one_hmac: hmac_vector -> Stack unit (fun _ -> True) (fun _ _ _ -> True) let test_one_hmac vec = let ha, (LB keylen key), (LB datalen data), (LB expectedlen expected) = vec in if Spec.Hash.Definitions.is_shake ha then failwith "unsupported shake algorithm" else if expectedlen <> Hacl.Hash.Definitions.hash_len ha then failwith "Wrong length of expected tag\n" else if not (keysized ha keylen) then failwith "Keysized predicate not satisfied\n" else if not (datalen <= 0xfffffffful - Hacl.Hash.Definitions.block_len ha) then failwith "Datalen predicate not satisfied\n" else if EverCrypt.HMAC.is_supported_alg ha then begin push_frame(); assert (Spec.Agile.HMAC.keysized ha (v keylen)); assert (v datalen + Spec.Hash.Definitions.block_length ha < pow2 32); B.recall key; B.recall data; let computed = B.alloca 0uy (Hacl.Hash.Definitions.hash_len ha) in EverCrypt.HMAC.compute ha computed key keylen data datalen; let str = string_of_alg ha in B.recall expected; TestLib.compare_and_print str expected computed (Hacl.Hash.Definitions.hash_len ha); pop_frame() end let test_hmac = test_many !$"HMAC" test_one_hmac /// HKDF /// ---- val test_one_hkdf: hkdf_vector -> Stack unit (fun _ -> True) (fun _ _ _ -> True) let test_one_hkdf vec = let ha, (LB ikmlen ikm), (LB saltlen salt), (LB infolen info), (LB prklen expected_prk), (LB okmlen expected_okm) = vec in if Spec.Hash.Definitions.is_shake ha then failwith "unsupported shake algorithm" else if prklen <> Hacl.Hash.Definitions.hash_len ha then failwith "Wrong length of expected PRK\n" else if okmlen > 255ul * Hacl.Hash.Definitions.hash_len ha then failwith "Wrong output length\n" else if not (keysized ha saltlen) then failwith "Saltlen is not keysized\n" else if not (keysized ha prklen) then failwith "Prklen is not keysized\n" else if not (ikmlen <= 0xfffffffful - Hacl.Hash.Definitions.block_len ha) then failwith "ikmlen is too large\n" else if not (infolen <= 0xfffffffful - Hacl.Hash.Definitions.(block_len ha + hash_len ha + 1ul)) then failwith "infolen is too large\n" else if EverCrypt.HMAC.is_supported_alg ha then begin push_frame(); assert (Spec.Agile.HMAC.keysized ha (v saltlen)); assert (v ikmlen + Spec.Hash.Definitions.block_length ha < pow2 32); assert Spec.Hash.Definitions.(hash_length ha + v infolen + 1 + block_length ha < pow2 32); B.recall salt; B.recall ikm; B.recall info; let str = string_of_alg ha in let computed_prk = B.alloca 0uy (Hacl.Hash.Definitions.hash_len ha) in EverCrypt.HKDF.extract ha computed_prk salt saltlen ikm ikmlen; B.recall expected_prk; TestLib.compare_and_print str expected_prk computed_prk (Hacl.Hash.Definitions.hash_len ha); let computed_okm = B.alloca 0uy (okmlen + 1ul) in let computed_okm = B.sub computed_okm 0ul okmlen in EverCrypt.HKDF.expand ha computed_okm computed_prk prklen info infolen okmlen; B.recall expected_okm; TestLib.compare_and_print str expected_okm computed_okm okmlen; pop_frame() end let test_hkdf = test_many !$"HKDF" test_one_hkdf /// Chacha20 /// -------- friend Lib.IntTypes let test_one_chacha20 (v: chacha20_vector): Stack unit (fun _ -> True) (fun _ _ _ -> True) = let (LB key_len key), (LB iv_len iv), ctr, (LB plain_len plain), (LB cipher_len cipher) = v in if cipher_len = 0xfffffffful then failwith "Cipher too long" else if cipher_len <> plain_len then failwith "Cipher len and plain len don't match" else if key_len <> 32ul then failwith "invalid key len" else if iv_len <> 12ul then failwith "invalid iv len" else if not (ctr <= 0xfffffffful - cipher_len / 64ul) then failwith "invalid len" else begin push_frame (); B.recall key; B.recall iv; B.recall plain; B.recall cipher; let cipher' = B.alloca 0uy (cipher_len + 1ul) in let cipher' = B.sub cipher' 0ul cipher_len in EverCrypt.Cipher.chacha20 plain_len cipher' plain key iv ctr; TestLib.compare_and_print !$"of ChaCha20 message" cipher cipher' cipher_len; pop_frame () end let test_chacha20 = test_many !$"CHACHA20" test_one_chacha20 /// Using generated vectors in the vectors/ directory /// ================================================= /// Poly1305 /// -------- let test_one_poly1305 (v: Test.Vectors.Poly1305.vector): Stack unit (fun _ -> True) (fun _ _ _ -> True) = let open Test.Vectors.Poly1305 in let Vector tag tag_len key key_len input input_len = v in push_frame (); if not (4294967295ul `U32.sub` 16ul `U32.gte` input_len) then failwith "Error: skipping a test_poly1305 instance because bounds do not hold\n" else begin B.recall key; B.recall tag; B.recall input; let h0 = get () in let dst = B.alloca 0uy 16ul in let h1 = get () in B.recall input; B.recall key; B.recall tag; if key_len = 32ul then EverCrypt.Poly1305.mac dst input input_len key; B.recall tag; if tag_len = 16ul then TestLib.compare_and_print !$"Poly1305" tag dst 16ul end; pop_frame () let test_poly1305 () : Stack unit (fun _ -> True) (fun _ _ _ -> True) = test_many !$"poly1305" test_one_poly1305 Test.Vectors.Poly1305.(LB vectors_len vectors) /// Curve25519 /// ---------- let test_one_curve25519 (v: Test.Vectors.Curve25519.vector): Stack unit (fun _ -> True) (fun _ _ _ -> True) = let open Test.Vectors.Curve25519 in let Vector result result_len public public_len private_ private__len valid = v in push_frame (); B.recall result; B.recall public; B.recall private_; let h0 = get () in let dst = B.alloca 0uy 32ul in let h1 = get () in B.recall result; B.recall public; B.recall private_; if public_len = 32ul && private__len = 32ul then EverCrypt.Curve25519.scalarmult dst private_ public; B.recall result; if result_len = 32ul && valid then TestLib.compare_and_print !$"Curve25519" result dst 32ul; pop_frame () let test_curve25519 () : Stack unit (fun _ -> True) (fun _ _ _ -> True) = test_many !$"curve25519" test_one_curve25519 Test.Vectors.Curve25519.(LB vectors_len vectors) /// Chacha20-Poly1305 /// ----------------- #push-options "--z3rlimit 32"
{ "checked_file": "/", "dependencies": [ "TestLib.fsti.checked", "Test.Vectors.Poly1305.fst.checked", "Test.Vectors.Curve25519.fst.checked", "Test.Vectors.Chacha20Poly1305.fst.checked", "Test.Vectors.fst.checked", "Test.Lowstarize.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Failure.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "EverCrypt.Poly1305.fsti.checked", "EverCrypt.HMAC.fsti.checked", "EverCrypt.HKDF.fsti.checked", "EverCrypt.Hash.Incremental.fst.checked", "EverCrypt.Hash.fsti.checked", "EverCrypt.Curve25519.fsti.checked", "EverCrypt.Cipher.fsti.checked", "EverCrypt.Chacha20Poly1305.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "Test.NoHeap.fst" }
[ { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "H" }, { "abbrev": false, "full_module": "Test", "short_module": null }, { "abbrev": false, "full_module": "Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Test.Vectors.Chacha20Poly1305.vector -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Test.Vectors.Chacha20Poly1305.vector", "LowStar.Buffer.buffer", "FStar.UInt8.t", "LowStar.Monotonic.Buffer.recallable", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.l_and", "LowStar.Monotonic.Buffer.disjoint", "Prims.op_Negation", "FStar.UInt32.__uint_to_t", "Test.NoHeap.failwith", "Prims.unit", "Prims.bool", "FStar.UInt32.gte", "FStar.UInt32.sub", "FStar.UInt32.lte", "FStar.UInt32.div", "FStar.UInt32.add", "FStar.HyperStack.ST.pop_frame", "TestLib.compare_and_print", "Test.NoHeap.op_Bang_Dollar", "EverCrypt.Chacha20Poly1305.aead_decrypt", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.sub", "FStar.Ghost.hide", "EverCrypt.Chacha20Poly1305.aead_encrypt", "Prims.eq2", "Prims.nat", "FStar.UInt32.uint_to_t", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.UInt8.__uint_to_t", "FStar.HyperStack.ST.push_frame", "LowStar.Monotonic.Buffer.recall", "FStar.Monotonic.HyperStack.mem", "Prims.l_True" ]
[]
false
true
false
false
false
let test_one_chacha20poly1305 (v: Test.Vectors.Chacha20Poly1305.vector) : Stack unit (fun _ -> True) (fun _ _ _ -> True) =
let Test.Vectors.Chacha20Poly1305.Vector cipher_and_tag cipher_and_tag_len plain plain_len aad aad_len nonce nonce_len key key_len = v in if not (key_len = 32ul) then failwith "chacha20poly1305: not (key_len = 32ul)" else if not (nonce_len = 12ul) then failwith "chacha20poly1305: not (nonce_len = 12ul)" else if not ((4294967295ul `U32.sub` 16ul) `U32.gte` plain_len) then failwith "chacha20poly1305: not ((4294967295ul `U32.sub` 16ul) `U32.gte` plain_len)" else if not ((plain_len `U32.div` 64ul) `U32.lte` (4294967295ul `U32.sub` aad_len)) then failwith "chacha20poly1305: not ((plain_len `U32.div` 64ul) `U32.lte` (4294967295ul `U32.sub` aad_len))" else if not (cipher_and_tag_len = plain_len `U32.add` 16ul) then failwith "chacha20poly1305: not (cipher_and_tag_len = plain_len `U32.add` 16ul)" else (B.recall plain; B.recall cipher_and_tag; B.recall aad; B.recall nonce; B.recall key; push_frame (); let tmp = B.alloca 0uy (plain_len `U32.add` 16ul) in let tmp_msg' = B.sub tmp 0ul plain_len in let tag' = B.sub tmp plain_len 16ul in EverCrypt.Chacha20Poly1305.aead_encrypt key nonce aad_len aad plain_len plain tmp_msg' tag'; TestLib.compare_and_print !$"chacha20poly1305 cipher and tag" cipher_and_tag tmp cipher_and_tag_len; let cipher = B.sub cipher_and_tag 0ul plain_len in let tag = B.sub cipher_and_tag plain_len 16ul in let res = EverCrypt.Chacha20Poly1305.aead_decrypt key nonce aad_len aad plain_len tmp_msg' cipher tag in if res = 0ul then TestLib.compare_and_print !$"chacha20poly1305 plain" plain tmp_msg' plain_len else failwith "Failure: chacha20poly1305 aead_decrypt returned nonzero value"; pop_frame ())
false
MerkleTree.Low.fst
MerkleTree.Low.mt_verify_pre_nst
val mt_verify_pre_nst: mt:merkle_tree -> k:offset_t -> j:offset_t -> p:path -> rt:(hash #(MT?.hash_size mt)) -> Tot bool
val mt_verify_pre_nst: mt:merkle_tree -> k:offset_t -> j:offset_t -> p:path -> rt:(hash #(MT?.hash_size mt)) -> Tot bool
let mt_verify_pre_nst mt k j p rt = k < j && offsets_connect (MT?.offset mt) k && offsets_connect (MT?.offset mt) j && MT?.hash_size mt = Path?.hash_size p && ([@inline_let] let k = split_offset (MT?.offset mt) k in [@inline_let] let j = split_offset (MT?.offset mt) j in // We need to add one since the first element is the hash to verify. V.size_of (Path?.hashes p) = 1ul + mt_path_length 0ul k j false)
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 67, "end_line": 2896, "start_col": 0, "start_line": 2888 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after))))) #push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1" let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) #pop-options // For given a target index `k`, the number of elements (in the tree) `j`, // and a boolean flag (to check the existence of rightmost hashes), we can // calculate a required Merkle path length. // // `mt_path_length` is a postcondition of `mt_get_path`, and a precondition // of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`. private val mt_path_length_step: k:index_t -> j:index_t{k <= j} -> actd:bool -> Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd}) let mt_path_length_step k j actd = if j = 0ul then 0ul else (if k % 2ul = 0ul then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul) else 1ul) private inline_for_extraction val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j)) #push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1" let rec mt_path_length lv k j actd = if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd) #pop-options val mt_get_path_length: mtr:HH.rid -> p:const_path_p -> HST.ST uint32_t (requires (fun h0 -> path_safe h0 mtr (CB.cast p))) (ensures (fun h0 _ h1 -> True)) let mt_get_path_length mtr p = let pd = !*(CB.cast p) in V.size_of (Path?.hashes pd) private inline_for_extraction val mt_make_path_step: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\ V.size_of (phashes h1 p) <= lv + 2ul /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_make_path_step (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2" let mt_make_path_step #hsz lv mtr hs rhs i j k p actd = let pth = !*p in let hh0 = HST.get () in let ofs = offset_of i in if k % 2ul = 1ul then begin hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs)))); assert(Path?.hash_size pth = hsz); mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs)) end else begin if k = j then () else if k + 1ul = j then (if actd then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv))); mt_path_insert mtr p (V.index rhs lv))) else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs)))); mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs))) end #pop-options private inline_for_extraction val mt_get_path_step_pre_nst: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:path -> i:uint32_t -> Tot bool let mt_get_path_step_pre_nst #hsz mtr p i = i < V.size_of (Path?.hashes p) val mt_get_path_step_pre: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST bool (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ mt_get_path_step_pre_nst #hsz mtr pv i))) (ensures (fun _ _ _ -> True)) let mt_get_path_step_pre #hsz mtr p i = let p = CB.cast p in mt_get_path_step_pre_nst #hsz mtr !*p i val mt_get_path_step: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST (hash #hsz) (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ i < V.size_of (Path?.hashes pv)))) (ensures (fun h0 r h1 -> True )) let mt_get_path_step #hsz mtr p i = let pd = !*(CB.cast p) in V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i private val mt_get_path_: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length lv k j actd /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2" let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd = let hh0 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; let ofs = offset_of i in if j = 0ul then () else (mt_make_path_step lv mtr hs rhs i j k p actd; let hh1 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (lift_path hh1 mtr p) (MTH.mt_make_path_step (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd)); RV.rv_inv_preserved hs (path_loc p) hh0 hh1; RV.rv_inv_preserved rhs (path_loc p) hh0 hh1; RV.as_seq_preserved hs (path_loc p) hh0 hh1; RV.as_seq_preserved rhs (path_loc p) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1; assert (mt_safe_elts hh1 lv hs i j); mt_safe_elts_rec hh1 lv hs i j; mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p (if j % 2ul = 0ul then actd else true); let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv + 1) (RV.as_seq hh1 hs) (RV.as_seq hh1 rhs) (U32.v i / 2) (U32.v j / 2) (U32.v k / 2) (lift_path hh1 mtr p) (if U32.v j % 2 = 0 then actd else true))); assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd))) #pop-options private inline_for_extraction val mt_get_path_pre_nst: mtv:merkle_tree -> idx:offset_t -> p:path -> root:(hash #(MT?.hash_size mtv)) -> Tot bool let mt_get_path_pre_nst mtv idx p root = offsets_connect (MT?.offset mtv) idx && Path?.hash_size p = MT?.hash_size mtv && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in MT?.i mtv <= idx && idx < MT?.j mtv && V.size_of (Path?.hashes p) = 0ul) val mt_get_path_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:const_path_p -> root:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let dmt = B.get h0 mt 0 in let dp = B.get h0 p 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ Path?.hash_size dp = (Ghost.reveal hsz) /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun _ _ _ -> True)) let mt_get_path_pre #_ mt idx p root = let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_get_path_pre_nst mtv idx !*p root val mt_get_path_loc_union_helper: l1:loc -> l2:loc -> Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2) let mt_get_path_loc_union_helper l1 l2 = () // Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost // hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree // to the output path. #push-options "--z3rlimit 60" val mt_get_path: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:path_p -> root:hash #hsz -> HST.ST index_t (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let idx = split_offset (MT?.offset mtv0) idx in MT?.hash_size mtv0 = Ghost.reveal hsz /\ MT?.hash_size mtv1 = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\ // memory safety modifies (loc_union (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) h0 h1 /\ mt_safe h1 mt /\ path_safe h1 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h1 root /\ V.size_of (phashes h1 p) == 1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\ // correctness (let sj, sp, srt = MTH.mt_get_path (mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in sj == U32.v (MT?.j mtv1) /\ S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\ srt == Rgl?.r_repr (hreg hsz) h1 root))) #pop-options #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" let mt_get_path #hsz mt idx p root = let ncmt = CB.cast mt in let mtframe = B.frameOf ncmt in let hh0 = HST.get () in mt_get_root mt root; let mtv = !*ncmt in let hsz = MT?.hash_size mtv in let hh1 = HST.get () in path_safe_init_preserved mtframe p (B.loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) hh0 hh1; assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) == (mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root)); assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty); let idx = split_offset (MT?.offset mtv) idx in let i = MT?.i mtv in let ofs = offset_of (MT?.i mtv) in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in assert (mt_safe_elts hh1 0ul hs i j); assert (V.size_of (V.get hh1 hs 0ul) == j - ofs); assert (idx < j); hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs); hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs); hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs); let ih = V.index (V.index hs 0ul) (idx - ofs) in mt_path_insert #hsz mtframe p ih; let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtframe p) (MTH.path_insert (lift_path hh1 mtframe p) (S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs)))); Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2; mt_safe_preserved ncmt (path_loc p) hh1 hh2; mt_preserved ncmt (path_loc p) hh1 hh2; assert (V.size_of (phashes hh2 p) == 1ul); mt_get_path_ 0ul mtframe hs rhs i j idx p false; let hh3 = HST.get () in // memory safety mt_get_path_loc_union_helper (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p); Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3; mt_safe_preserved ncmt (path_loc p) hh2 hh3; mt_preserved ncmt (path_loc p) hh2 hh3; assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); assert (S.length (lift_path #hsz hh3 mtframe p) == S.length (lift_path #hsz hh2 mtframe p) + MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false); assert (modifies (loc_union (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) hh0 hh3); assert (mt_safe hh3 ncmt); assert (path_safe hh3 mtframe p); assert (Rgl?.r_inv (hreg hsz) hh3 root); assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); // correctness mt_safe_elts_spec hh2 0ul hs i j; assert (S.equal (lift_path hh3 mtframe p) (MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs) (U32.v i) (U32.v j) (U32.v idx) (lift_path hh2 mtframe p) false)); assert (MTH.mt_get_path (mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) == (U32.v (MT?.j (B.get hh3 ncmt 0)), lift_path hh3 mtframe p, Rgl?.r_repr (hreg hsz) hh3 root)); j #pop-options /// Flushing private val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) #push-options "--initial_fuel 2 --max_fuel 2" let mt_flush_to_modifies_rec_helper #hsz lv hs h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val mt_flush_to_: hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> pi:index_t -> i:index_t{i >= pi} -> j:Ghost.erased index_t{ Ghost.reveal j >= i && U32.v (Ghost.reveal j) < pow2 (32 - U32.v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs pi (Ghost.reveal j))) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1 /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i (Ghost.reveal j) /\ // correctness (mt_safe_elts_spec h0 lv hs pi (Ghost.reveal j); S.equal (RV.as_seq h1 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq h0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))))) (decreases (U32.v i)) #restart-solver #push-options "--z3rlimit 1500 --fuel 1 --ifuel 0" let rec mt_flush_to_ hsz lv hs pi i j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs pi (Ghost.reveal j); V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); let oi = offset_of i in let opi = offset_of pi in if oi = opi then mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j) else begin /// 1) Flush hashes at the level `lv`, where the new vector is /// not yet connected to `hs`. let ofs = oi - opi in let hvec = V.index hs lv in let flushed:(rvector (hreg hsz)) = rv_flush_inplace hvec ofs in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) flushed); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of flushed == Ghost.reveal j - offset_of i); // head updated mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 flushed) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) (U32.v ofs) (S.length (RV.as_seq hh0 (V.get hh0 hs lv))))); /// 2) Assign the flushed vector to `hs` at the level `lv`. RV.assign hs lv flushed; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == Ghost.reveal j - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector flushed) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector flushed) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 flushed) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 flushed); // if `lv = 31` then `pi <= i <= j < 2` thus `oi = opi`, // contradicting the branch. assert (lv + 1ul < merkle_tree_size_lg); assert (U32.v (Ghost.reveal j / 2ul) < pow2 (32 - U32.v (lv + 1ul))); assert (RV.rv_inv hh2 hs); assert (mt_safe_elts hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)); /// 3) Recursion mt_flush_to_ hsz (lv + 1ul) hs (pi / 2ul) (i / 2ul) (Ghost.hide (Ghost.reveal j / 2ul)); let hh3 = HST.get () in // 3-0) Memory safety brought from the postcondition of the recursion assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == Ghost.reveal j - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i (Ghost.reveal j); assert (mt_safe_elts hh3 lv hs i (Ghost.reveal j)); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv + 1) (RV.as_seq hh2 hs) (U32.v pi / 2) (U32.v i / 2) (U32.v (Ghost.reveal j) / 2))); mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j); MTH.mt_flush_to_rec (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))) end #pop-options // `mt_flush_to` flushes old hashes in the Merkle tree. It removes hash elements // from `MT?.i` to **`offset_of (idx - 1)`**, but maintains the tree structure, // i.e., the tree still holds some old internal hashes (compressed from old // hashes) which are required to generate Merkle paths for remaining hashes. // // Note that `mt_flush_to` (and `mt_flush`) always remain at least one base hash // elements. If there are `MT?.j` number of elements in the tree, because of the // precondition `MT?.i <= idx < MT?.j` we still have `idx`-th element after // flushing. private inline_for_extraction val mt_flush_to_pre_nst: mtv:merkle_tree -> idx:offset_t -> Tot bool let mt_flush_to_pre_nst mtv idx = offsets_connect (MT?.offset mtv) idx && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in idx >= MT?.i mtv && idx < MT?.j mtv) val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_flush_to_pre mt idx = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_flush_to_pre_nst mtv idx #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" val mt_flush_to: mt:mt_p -> idx:offset_t -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx)) (ensures (fun h0 _ h1 -> // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let off = MT?.offset mtv0 in let idx = split_offset off idx in MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_flush_to (mt_lift h0 mt) (U32.v idx) == mt_lift h1 mt))) let mt_flush_to mt idx = let hh0 = HST.get () in let mtv = !*mt in let offset = MT?.offset mtv in let j = MT?.j mtv in let hsz = MT?.hash_size mtv in let idx = split_offset offset idx in let hs = MT?.hs mtv in mt_flush_to_ hsz 0ul hs (MT?.i mtv) idx (Ghost.hide (MT?.j mtv)); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) idx (MT?.j mtv) hs (MT?.rhs_ok mtv) (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul hs idx (MT?.j mtv) (B.loc_buffer mt) hh1 hh2 #pop-options private inline_for_extraction val mt_flush_pre_nst: mt:merkle_tree -> Tot bool let mt_flush_pre_nst mt = MT?.j mt > MT?.i mt val mt_flush_pre: mt:const_mt_p -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_flush_pre mt = mt_flush_pre_nst !*(CB.cast mt) val mt_flush: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_flush_pre_nst (B.get h0 mt 0))) (ensures (fun h0 _ h1 -> let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_flush (mt_lift h0 mt) == mt_lift h1 mt)) #push-options "--z3rlimit 200 --initial_fuel 1 --max_fuel 1" let mt_flush mt = let mtv = !*mt in let off = MT?.offset mtv in let j = MT?.j mtv in let j1 = j - 1ul in assert (j1 < uint32_32_max); assert (off < uint64_max); assert (UInt.fits (U64.v off + U32.v j1) 64); let jo = join_offset off j1 in mt_flush_to mt jo #pop-options /// Retraction private val mt_retract_to_: #hsz:hash_size_t -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> lv:uint32_t{lv < V.size_of hs} -> i:index_t -> s:index_t -> j:index_t{i <= s && s <= j && v j < pow2 (U32.v (V.size_of hs) - v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety (modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1) /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i s /\ // correctness (mt_safe_elts_spec h0 lv hs i j; S.equal (RV.as_seq h1 hs) (MTH.mt_retract_to_ (RV.as_seq h0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) )) (decreases (U32.v merkle_tree_size_lg - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" private let rec mt_retract_to_ #hsz hs lv i s j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs i j; V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); if lv >= V.size_of hs then () else begin // 1) Retract hashes at level `lv`. let hvec = V.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in let retracted = RV.shrink hvec new_len in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) retracted); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of retracted == new_len); mt_safe_elts_preserved (lv + 1ul) hs (i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 retracted) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) 0 (U32.v new_len))); RV.assign hs lv retracted; let hh2 = HST.get() in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == s - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector retracted) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector retracted) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 retracted) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 retracted); if lv + 1ul < V.size_of hs then begin assert (mt_safe_elts hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul)); mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_retract_to_ hs (lv + 1ul) (i / 2ul) (s / 2ul) (j / 2ul); // 3-0) Memory safety brought from the postcondition of the recursion let hh3 = HST.get () in assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == s - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i s; assert (mt_safe_elts hh3 lv hs i s); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (U32.v lv + 1 < S.length (RV.as_seq hh3 hs) ==> S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh2 hs) (U32.v lv + 1) (U32.v i / 2) (U32.v s / 2) (U32.v j / 2))); assert (RV.rv_inv hh0 hs); assert (mt_safe_elts hh0 lv hs i j); mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) end else begin let hh3 = HST.get() in assert ((modifies (loc_union (RV.rv_loc_elems hh0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) hh0 hh3)); assert (RV.rv_inv hh3 hs /\ mt_safe_elts hh3 lv hs i s); mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) end end #pop-options private inline_for_extraction val mt_retract_to_pre_nst: mtv:merkle_tree -> r:offset_t -> Tot bool let mt_retract_to_pre_nst mtv r = offsets_connect (MT?.offset mtv) r && ([@inline_let] let r = split_offset (MT?.offset mtv) r in MT?.i mtv <= r && r < MT?.j mtv) val mt_retract_to_pre: mt:const_mt_p -> r:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_retract_to_pre mt r = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_retract_to_pre_nst mtv r #push-options "--z3rlimit 100" val mt_retract_to: mt:mt_p -> r:offset_t -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_retract_to_pre_nst (B.get h0 mt 0) r)) (ensures (fun h0 _ h1 -> // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let off = MT?.offset mtv0 in let r = split_offset off r in MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_retract_to (mt_lift h0 mt) (U32.v r) == mt_lift h1 mt))) let mt_retract_to mt r = let hh0 = HST.get () in let mtv = !*mt in let offset = MT?.offset mtv in let r = split_offset offset r in let hs = MT?.hs mtv in mt_retract_to_ hs 0ul (MT?.i mtv) (r + 1ul) (MT?.j mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (r+1ul) hs false (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul hs (MT?.i mtv) (r+1ul) (B.loc_buffer mt) hh1 hh2 #pop-options /// Client-side verification private val mt_verify_: #hsz:hash_size_t -> #hash_spec:MTS.hash_fun_t #(U32.v hsz) -> k:index_t -> j:index_t{k <= j} -> mtr:HH.rid -> p:const_path_p -> ppos:uint32_t -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> let p = CB.cast p in path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 acc /\ Path?.hash_size (B.get h0 p 0) = hsz /\ HH.disjoint (B.frameOf p) (B.frameOf acc) /\ HH.disjoint mtr (B.frameOf acc) /\ // Below is a very relaxed condition, // but sufficient to ensure (+) for uint32_t is sound. ppos <= 64ul - mt_path_length 0ul k j actd /\ ppos + mt_path_length 0ul k j actd <= V.size_of (phashes h0 p))) (ensures (fun h0 _ h1 -> let p = CB.cast p in // memory safety modifies (B.loc_all_regions_from false (B.frameOf acc)) h0 h1 /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness Rgl?.r_repr (hreg hsz) h1 acc == MTH.mt_verify_ #(U32.v hsz) #hash_spec (U32.v k) (U32.v j) (lift_path h0 mtr p) (U32.v ppos) (Rgl?.r_repr (hreg hsz) h0 acc) actd)) #push-options "--z3rlimit 200 --initial_fuel 1 --max_fuel 1" let rec mt_verify_ #hsz #hash_spec k j mtr p ppos acc actd hash_fun = let ncp:path_p = CB.cast p in let hh0 = HST.get () in if j = 0ul then () else (let nactd = actd || (j % 2ul = 1ul) in if k % 2ul = 0ul then begin if j = k || (j = k + 1ul && not actd) then mt_verify_ (k / 2ul) (j / 2ul) mtr p ppos acc nactd hash_fun else begin let ncpd = !*ncp in let phash = V.index (Path?.hashes ncpd) ppos in hash_fun acc phash acc; let hh1 = HST.get () in path_preserved mtr ncp (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; lift_path_index hh0 mtr ncp ppos; assert (Rgl?.r_repr (hreg hsz) hh1 acc == hash_spec (Rgl?.r_repr (hreg hsz) hh0 acc) (S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos))); mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun end end else begin let ncpd = !*ncp in let phash = V.index (Path?.hashes ncpd) ppos in hash_fun phash acc acc; let hh1 = HST.get () in path_preserved mtr ncp (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; lift_path_index hh0 mtr ncp ppos; assert (Rgl?.r_repr (hreg hsz) hh1 acc == hash_spec (S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos)) (Rgl?.r_repr (hreg hsz) hh0 acc)); mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun end) #pop-options private inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.merkle_tree -> k: MerkleTree.Low.offset_t -> j: MerkleTree.Low.offset_t -> p: MerkleTree.Low.path -> rt: MerkleTree.Low.Datastructures.hash -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.merkle_tree", "MerkleTree.Low.offset_t", "MerkleTree.Low.path", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.__proj__MT__item__hash_size", "Prims.op_AmpAmp", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W64", "MerkleTree.Low.offsets_connect", "MerkleTree.Low.__proj__MT__item__offset", "Prims.op_Equality", "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.__proj__Path__item__hash_size", "FStar.UInt32.t", "LowStar.Vector.size_of", "MerkleTree.Low.__proj__Path__item__hashes", "FStar.Integers.op_Plus", "FStar.Integers.W32", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.mt_path_length", "MerkleTree.Low.index_t", "MerkleTree.Low.split_offset", "Prims.bool" ]
[]
false
false
false
false
false
let mt_verify_pre_nst mt k j p rt =
k < j && offsets_connect (MT?.offset mt) k && offsets_connect (MT?.offset mt) j && MT?.hash_size mt = Path?.hash_size p && ([@@ inline_let ]let k = split_offset (MT?.offset mt) k in [@@ inline_let ]let j = split_offset (MT?.offset mt) j in V.size_of (Path?.hashes p) = 1ul + mt_path_length 0ul k j false)
false
Hacl.HPKE.Curve51_CP256_SHA512.fsti
Hacl.HPKE.Curve51_CP256_SHA512.cs
val cs:S.ciphersuite
val cs:S.ciphersuite
let cs:S.ciphersuite = (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_512)
{ "file_name": "code/hpke/Hacl.HPKE.Curve51_CP256_SHA512.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 102, "end_line": 10, "start_col": 0, "start_line": 10 }
module Hacl.HPKE.Curve51_CP256_SHA512 open Hacl.Impl.HPKE module S = Spec.Agile.HPKE module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash
{ "checked_file": "/", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Hacl.Impl.HPKE.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Curve51_CP256_SHA512.fsti" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": 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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Spec.Agile.HPKE.ciphersuite
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.Mktuple4", "Spec.Agile.DH.algorithm", "Spec.Agile.HPKE.hash_algorithm", "Spec.Agile.HPKE.aead", "Spec.Hash.Definitions.hash_alg", "Spec.Agile.DH.DH_Curve25519", "Spec.Hash.Definitions.SHA2_256", "Spec.Agile.HPKE.Seal", "Spec.Agile.AEAD.CHACHA20_POLY1305", "Spec.Hash.Definitions.SHA2_512" ]
[]
false
false
false
true
false
let cs:S.ciphersuite =
(DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_512)
false
MerkleTree.Low.fst
MerkleTree.Low.mt_verify_pre
val mt_verify_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> k:uint64_t -> j:uint64_t -> mtr:HH.rid -> p:const_path_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let mtv0 = B.get h0 mt 0 in MT?.hash_size mtv0 = Ghost.reveal hsz /\ mt_safe h0 mt /\ path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HST.is_eternal_region (B.frameOf rt) /\ HH.disjoint (B.frameOf p) (B.frameOf rt) /\ HH.disjoint mtr (B.frameOf rt))) (ensures (fun _ _ _ -> True))
val mt_verify_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> k:uint64_t -> j:uint64_t -> mtr:HH.rid -> p:const_path_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let mtv0 = B.get h0 mt 0 in MT?.hash_size mtv0 = Ghost.reveal hsz /\ mt_safe h0 mt /\ path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HST.is_eternal_region (B.frameOf rt) /\ HH.disjoint (B.frameOf p) (B.frameOf rt) /\ HH.disjoint mtr (B.frameOf rt))) (ensures (fun _ _ _ -> True))
let mt_verify_pre #hsz mt k j mtr p rt = let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_verify_pre_nst mtv k j !*p rt
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 34, "end_line": 2922, "start_col": 0, "start_line": 2918 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after))))) #push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1" let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) #pop-options // For given a target index `k`, the number of elements (in the tree) `j`, // and a boolean flag (to check the existence of rightmost hashes), we can // calculate a required Merkle path length. // // `mt_path_length` is a postcondition of `mt_get_path`, and a precondition // of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`. private val mt_path_length_step: k:index_t -> j:index_t{k <= j} -> actd:bool -> Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd}) let mt_path_length_step k j actd = if j = 0ul then 0ul else (if k % 2ul = 0ul then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul) else 1ul) private inline_for_extraction val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j)) #push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1" let rec mt_path_length lv k j actd = if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd) #pop-options val mt_get_path_length: mtr:HH.rid -> p:const_path_p -> HST.ST uint32_t (requires (fun h0 -> path_safe h0 mtr (CB.cast p))) (ensures (fun h0 _ h1 -> True)) let mt_get_path_length mtr p = let pd = !*(CB.cast p) in V.size_of (Path?.hashes pd) private inline_for_extraction val mt_make_path_step: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\ V.size_of (phashes h1 p) <= lv + 2ul /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_make_path_step (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2" let mt_make_path_step #hsz lv mtr hs rhs i j k p actd = let pth = !*p in let hh0 = HST.get () in let ofs = offset_of i in if k % 2ul = 1ul then begin hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs)))); assert(Path?.hash_size pth = hsz); mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs)) end else begin if k = j then () else if k + 1ul = j then (if actd then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv))); mt_path_insert mtr p (V.index rhs lv))) else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs)))); mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs))) end #pop-options private inline_for_extraction val mt_get_path_step_pre_nst: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:path -> i:uint32_t -> Tot bool let mt_get_path_step_pre_nst #hsz mtr p i = i < V.size_of (Path?.hashes p) val mt_get_path_step_pre: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST bool (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ mt_get_path_step_pre_nst #hsz mtr pv i))) (ensures (fun _ _ _ -> True)) let mt_get_path_step_pre #hsz mtr p i = let p = CB.cast p in mt_get_path_step_pre_nst #hsz mtr !*p i val mt_get_path_step: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST (hash #hsz) (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ i < V.size_of (Path?.hashes pv)))) (ensures (fun h0 r h1 -> True )) let mt_get_path_step #hsz mtr p i = let pd = !*(CB.cast p) in V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i private val mt_get_path_: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length lv k j actd /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2" let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd = let hh0 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; let ofs = offset_of i in if j = 0ul then () else (mt_make_path_step lv mtr hs rhs i j k p actd; let hh1 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (lift_path hh1 mtr p) (MTH.mt_make_path_step (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd)); RV.rv_inv_preserved hs (path_loc p) hh0 hh1; RV.rv_inv_preserved rhs (path_loc p) hh0 hh1; RV.as_seq_preserved hs (path_loc p) hh0 hh1; RV.as_seq_preserved rhs (path_loc p) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1; assert (mt_safe_elts hh1 lv hs i j); mt_safe_elts_rec hh1 lv hs i j; mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p (if j % 2ul = 0ul then actd else true); let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv + 1) (RV.as_seq hh1 hs) (RV.as_seq hh1 rhs) (U32.v i / 2) (U32.v j / 2) (U32.v k / 2) (lift_path hh1 mtr p) (if U32.v j % 2 = 0 then actd else true))); assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd))) #pop-options private inline_for_extraction val mt_get_path_pre_nst: mtv:merkle_tree -> idx:offset_t -> p:path -> root:(hash #(MT?.hash_size mtv)) -> Tot bool let mt_get_path_pre_nst mtv idx p root = offsets_connect (MT?.offset mtv) idx && Path?.hash_size p = MT?.hash_size mtv && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in MT?.i mtv <= idx && idx < MT?.j mtv && V.size_of (Path?.hashes p) = 0ul) val mt_get_path_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:const_path_p -> root:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let dmt = B.get h0 mt 0 in let dp = B.get h0 p 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ Path?.hash_size dp = (Ghost.reveal hsz) /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun _ _ _ -> True)) let mt_get_path_pre #_ mt idx p root = let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_get_path_pre_nst mtv idx !*p root val mt_get_path_loc_union_helper: l1:loc -> l2:loc -> Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2) let mt_get_path_loc_union_helper l1 l2 = () // Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost // hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree // to the output path. #push-options "--z3rlimit 60" val mt_get_path: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:path_p -> root:hash #hsz -> HST.ST index_t (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let idx = split_offset (MT?.offset mtv0) idx in MT?.hash_size mtv0 = Ghost.reveal hsz /\ MT?.hash_size mtv1 = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\ // memory safety modifies (loc_union (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) h0 h1 /\ mt_safe h1 mt /\ path_safe h1 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h1 root /\ V.size_of (phashes h1 p) == 1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\ // correctness (let sj, sp, srt = MTH.mt_get_path (mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in sj == U32.v (MT?.j mtv1) /\ S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\ srt == Rgl?.r_repr (hreg hsz) h1 root))) #pop-options #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" let mt_get_path #hsz mt idx p root = let ncmt = CB.cast mt in let mtframe = B.frameOf ncmt in let hh0 = HST.get () in mt_get_root mt root; let mtv = !*ncmt in let hsz = MT?.hash_size mtv in let hh1 = HST.get () in path_safe_init_preserved mtframe p (B.loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) hh0 hh1; assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) == (mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root)); assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty); let idx = split_offset (MT?.offset mtv) idx in let i = MT?.i mtv in let ofs = offset_of (MT?.i mtv) in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in assert (mt_safe_elts hh1 0ul hs i j); assert (V.size_of (V.get hh1 hs 0ul) == j - ofs); assert (idx < j); hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs); hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs); hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs); let ih = V.index (V.index hs 0ul) (idx - ofs) in mt_path_insert #hsz mtframe p ih; let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtframe p) (MTH.path_insert (lift_path hh1 mtframe p) (S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs)))); Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2; mt_safe_preserved ncmt (path_loc p) hh1 hh2; mt_preserved ncmt (path_loc p) hh1 hh2; assert (V.size_of (phashes hh2 p) == 1ul); mt_get_path_ 0ul mtframe hs rhs i j idx p false; let hh3 = HST.get () in // memory safety mt_get_path_loc_union_helper (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p); Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3; mt_safe_preserved ncmt (path_loc p) hh2 hh3; mt_preserved ncmt (path_loc p) hh2 hh3; assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); assert (S.length (lift_path #hsz hh3 mtframe p) == S.length (lift_path #hsz hh2 mtframe p) + MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false); assert (modifies (loc_union (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) hh0 hh3); assert (mt_safe hh3 ncmt); assert (path_safe hh3 mtframe p); assert (Rgl?.r_inv (hreg hsz) hh3 root); assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); // correctness mt_safe_elts_spec hh2 0ul hs i j; assert (S.equal (lift_path hh3 mtframe p) (MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs) (U32.v i) (U32.v j) (U32.v idx) (lift_path hh2 mtframe p) false)); assert (MTH.mt_get_path (mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) == (U32.v (MT?.j (B.get hh3 ncmt 0)), lift_path hh3 mtframe p, Rgl?.r_repr (hreg hsz) hh3 root)); j #pop-options /// Flushing private val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) #push-options "--initial_fuel 2 --max_fuel 2" let mt_flush_to_modifies_rec_helper #hsz lv hs h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val mt_flush_to_: hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> pi:index_t -> i:index_t{i >= pi} -> j:Ghost.erased index_t{ Ghost.reveal j >= i && U32.v (Ghost.reveal j) < pow2 (32 - U32.v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs pi (Ghost.reveal j))) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1 /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i (Ghost.reveal j) /\ // correctness (mt_safe_elts_spec h0 lv hs pi (Ghost.reveal j); S.equal (RV.as_seq h1 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq h0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))))) (decreases (U32.v i)) #restart-solver #push-options "--z3rlimit 1500 --fuel 1 --ifuel 0" let rec mt_flush_to_ hsz lv hs pi i j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs pi (Ghost.reveal j); V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); let oi = offset_of i in let opi = offset_of pi in if oi = opi then mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j) else begin /// 1) Flush hashes at the level `lv`, where the new vector is /// not yet connected to `hs`. let ofs = oi - opi in let hvec = V.index hs lv in let flushed:(rvector (hreg hsz)) = rv_flush_inplace hvec ofs in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) flushed); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of flushed == Ghost.reveal j - offset_of i); // head updated mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 flushed) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) (U32.v ofs) (S.length (RV.as_seq hh0 (V.get hh0 hs lv))))); /// 2) Assign the flushed vector to `hs` at the level `lv`. RV.assign hs lv flushed; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == Ghost.reveal j - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector flushed) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector flushed) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 flushed) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 flushed); // if `lv = 31` then `pi <= i <= j < 2` thus `oi = opi`, // contradicting the branch. assert (lv + 1ul < merkle_tree_size_lg); assert (U32.v (Ghost.reveal j / 2ul) < pow2 (32 - U32.v (lv + 1ul))); assert (RV.rv_inv hh2 hs); assert (mt_safe_elts hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)); /// 3) Recursion mt_flush_to_ hsz (lv + 1ul) hs (pi / 2ul) (i / 2ul) (Ghost.hide (Ghost.reveal j / 2ul)); let hh3 = HST.get () in // 3-0) Memory safety brought from the postcondition of the recursion assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == Ghost.reveal j - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i (Ghost.reveal j); assert (mt_safe_elts hh3 lv hs i (Ghost.reveal j)); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv + 1) (RV.as_seq hh2 hs) (U32.v pi / 2) (U32.v i / 2) (U32.v (Ghost.reveal j) / 2))); mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j); MTH.mt_flush_to_rec (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)); assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_flush_to_ (U32.v lv) (RV.as_seq hh0 hs) (U32.v pi) (U32.v i) (U32.v (Ghost.reveal j)))) end #pop-options // `mt_flush_to` flushes old hashes in the Merkle tree. It removes hash elements // from `MT?.i` to **`offset_of (idx - 1)`**, but maintains the tree structure, // i.e., the tree still holds some old internal hashes (compressed from old // hashes) which are required to generate Merkle paths for remaining hashes. // // Note that `mt_flush_to` (and `mt_flush`) always remain at least one base hash // elements. If there are `MT?.j` number of elements in the tree, because of the // precondition `MT?.i <= idx < MT?.j` we still have `idx`-th element after // flushing. private inline_for_extraction val mt_flush_to_pre_nst: mtv:merkle_tree -> idx:offset_t -> Tot bool let mt_flush_to_pre_nst mtv idx = offsets_connect (MT?.offset mtv) idx && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in idx >= MT?.i mtv && idx < MT?.j mtv) val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_flush_to_pre mt idx = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_flush_to_pre_nst mtv idx #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" val mt_flush_to: mt:mt_p -> idx:offset_t -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx)) (ensures (fun h0 _ h1 -> // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let off = MT?.offset mtv0 in let idx = split_offset off idx in MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_flush_to (mt_lift h0 mt) (U32.v idx) == mt_lift h1 mt))) let mt_flush_to mt idx = let hh0 = HST.get () in let mtv = !*mt in let offset = MT?.offset mtv in let j = MT?.j mtv in let hsz = MT?.hash_size mtv in let idx = split_offset offset idx in let hs = MT?.hs mtv in mt_flush_to_ hsz 0ul hs (MT?.i mtv) idx (Ghost.hide (MT?.j mtv)); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) idx (MT?.j mtv) hs (MT?.rhs_ok mtv) (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul hs idx (MT?.j mtv) (B.loc_buffer mt) hh1 hh2 #pop-options private inline_for_extraction val mt_flush_pre_nst: mt:merkle_tree -> Tot bool let mt_flush_pre_nst mt = MT?.j mt > MT?.i mt val mt_flush_pre: mt:const_mt_p -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_flush_pre mt = mt_flush_pre_nst !*(CB.cast mt) val mt_flush: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_flush_pre_nst (B.get h0 mt 0))) (ensures (fun h0 _ h1 -> let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_flush (mt_lift h0 mt) == mt_lift h1 mt)) #push-options "--z3rlimit 200 --initial_fuel 1 --max_fuel 1" let mt_flush mt = let mtv = !*mt in let off = MT?.offset mtv in let j = MT?.j mtv in let j1 = j - 1ul in assert (j1 < uint32_32_max); assert (off < uint64_max); assert (UInt.fits (U64.v off + U32.v j1) 64); let jo = join_offset off j1 in mt_flush_to mt jo #pop-options /// Retraction private val mt_retract_to_: #hsz:hash_size_t -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> lv:uint32_t{lv < V.size_of hs} -> i:index_t -> s:index_t -> j:index_t{i <= s && s <= j && v j < pow2 (U32.v (V.size_of hs) - v lv)} -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ mt_safe_elts h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety (modifies (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) h0 h1) /\ RV.rv_inv h1 hs /\ mt_safe_elts h1 lv hs i s /\ // correctness (mt_safe_elts_spec h0 lv hs i j; S.equal (RV.as_seq h1 hs) (MTH.mt_retract_to_ (RV.as_seq h0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) )) (decreases (U32.v merkle_tree_size_lg - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" private let rec mt_retract_to_ #hsz hs lv i s j = let hh0 = HST.get () in // Base conditions mt_safe_elts_rec hh0 lv hs i j; V.loc_vector_within_included hs 0ul lv; V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); if lv >= V.size_of hs then () else begin // 1) Retract hashes at level `lv`. let hvec = V.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in let retracted = RV.shrink hvec new_len in let hh1 = HST.get () in // 1-0) Basic disjointness conditions for `RV.assign` V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall_preserved hs 0ul lv (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; V.forall_preserved hs (lv + 1ul) (V.size_of hs) (fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec) (Rgl?.region_of (hvreg hsz) b)) (RV.loc_rvector hvec) hh0 hh1; assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) retracted); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of retracted == new_len); mt_safe_elts_preserved (lv + 1ul) hs (i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); assert (rv_itself_inv hh1 hs); assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 retracted) (S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) 0 (U32.v new_len))); RV.assign hs lv retracted; let hh2 = HST.get() in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == s - offset_of i); mt_safe_elts_preserved (lv + 1ul) hs (i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector retracted) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector retracted) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 retracted) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 retracted); if lv + 1ul < V.size_of hs then begin assert (mt_safe_elts hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul)); mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_retract_to_ hs (lv + 1ul) (i / 2ul) (s / 2ul) (j / 2ul); // 3-0) Memory safety brought from the postcondition of the recursion let hh3 = HST.get () in assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))) hh0 hh3); mt_flush_to_modifies_rec_helper lv hs hh0; V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); V.loc_vector_within_included hs lv (lv + 1ul); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); V.get_preserved hs lv (loc_union (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == s - offset_of i); assert (RV.rv_inv hh3 hs); mt_safe_elts_constr hh3 lv hs i s; assert (mt_safe_elts hh3 lv hs i s); // 3-1) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (U32.v lv + 1 < S.length (RV.as_seq hh3 hs) ==> S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh2 hs) (U32.v lv + 1) (U32.v i / 2) (U32.v s / 2) (U32.v j / 2))); assert (RV.rv_inv hh0 hs); assert (mt_safe_elts hh0 lv hs i j); mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) end else begin let hh3 = HST.get() in assert ((modifies (loc_union (RV.rv_loc_elems hh0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) hh0 hh3)); assert (RV.rv_inv hh3 hs /\ mt_safe_elts hh3 lv hs i s); mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (RV.as_seq hh3 hs) (MTH.mt_retract_to_ (RV.as_seq hh0 hs) (U32.v lv) (U32.v i) (U32.v s) (U32.v j))) end end #pop-options private inline_for_extraction val mt_retract_to_pre_nst: mtv:merkle_tree -> r:offset_t -> Tot bool let mt_retract_to_pre_nst mtv r = offsets_connect (MT?.offset mtv) r && ([@inline_let] let r = split_offset (MT?.offset mtv) r in MT?.i mtv <= r && r < MT?.j mtv) val mt_retract_to_pre: mt:const_mt_p -> r:offset_t -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True)) let mt_retract_to_pre mt r = let mt = CB.cast mt in let h0 = HST.get() in let mtv = !*mt in mt_retract_to_pre_nst mtv r #push-options "--z3rlimit 100" val mt_retract_to: mt:mt_p -> r:offset_t -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt /\ mt_retract_to_pre_nst (B.get h0 mt 0) r)) (ensures (fun h0 _ h1 -> // memory safety modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ // correctness (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let off = MT?.offset mtv0 in let r = split_offset off r in MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ MTH.mt_retract_to (mt_lift h0 mt) (U32.v r) == mt_lift h1 mt))) let mt_retract_to mt r = let hh0 = HST.get () in let mtv = !*mt in let offset = MT?.offset mtv in let r = split_offset offset r in let hs = MT?.hs mtv in mt_retract_to_ hs 0ul (MT?.i mtv) (r + 1ul) (MT?.j mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (r+1ul) hs false (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul hs (MT?.i mtv) (r+1ul) (B.loc_buffer mt) hh1 hh2 #pop-options /// Client-side verification private val mt_verify_: #hsz:hash_size_t -> #hash_spec:MTS.hash_fun_t #(U32.v hsz) -> k:index_t -> j:index_t{k <= j} -> mtr:HH.rid -> p:const_path_p -> ppos:uint32_t -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> let p = CB.cast p in path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 acc /\ Path?.hash_size (B.get h0 p 0) = hsz /\ HH.disjoint (B.frameOf p) (B.frameOf acc) /\ HH.disjoint mtr (B.frameOf acc) /\ // Below is a very relaxed condition, // but sufficient to ensure (+) for uint32_t is sound. ppos <= 64ul - mt_path_length 0ul k j actd /\ ppos + mt_path_length 0ul k j actd <= V.size_of (phashes h0 p))) (ensures (fun h0 _ h1 -> let p = CB.cast p in // memory safety modifies (B.loc_all_regions_from false (B.frameOf acc)) h0 h1 /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness Rgl?.r_repr (hreg hsz) h1 acc == MTH.mt_verify_ #(U32.v hsz) #hash_spec (U32.v k) (U32.v j) (lift_path h0 mtr p) (U32.v ppos) (Rgl?.r_repr (hreg hsz) h0 acc) actd)) #push-options "--z3rlimit 200 --initial_fuel 1 --max_fuel 1" let rec mt_verify_ #hsz #hash_spec k j mtr p ppos acc actd hash_fun = let ncp:path_p = CB.cast p in let hh0 = HST.get () in if j = 0ul then () else (let nactd = actd || (j % 2ul = 1ul) in if k % 2ul = 0ul then begin if j = k || (j = k + 1ul && not actd) then mt_verify_ (k / 2ul) (j / 2ul) mtr p ppos acc nactd hash_fun else begin let ncpd = !*ncp in let phash = V.index (Path?.hashes ncpd) ppos in hash_fun acc phash acc; let hh1 = HST.get () in path_preserved mtr ncp (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; lift_path_index hh0 mtr ncp ppos; assert (Rgl?.r_repr (hreg hsz) hh1 acc == hash_spec (Rgl?.r_repr (hreg hsz) hh0 acc) (S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos))); mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun end end else begin let ncpd = !*ncp in let phash = V.index (Path?.hashes ncpd) ppos in hash_fun phash acc acc; let hh1 = HST.get () in path_preserved mtr ncp (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; lift_path_index hh0 mtr ncp ppos; assert (Rgl?.r_repr (hreg hsz) hh1 acc == hash_spec (S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos)) (Rgl?.r_repr (hreg hsz) hh0 acc)); mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun end) #pop-options private inline_for_extraction val mt_verify_pre_nst: mt:merkle_tree -> k:offset_t -> j:offset_t -> p:path -> rt:(hash #(MT?.hash_size mt)) -> Tot bool let mt_verify_pre_nst mt k j p rt = k < j && offsets_connect (MT?.offset mt) k && offsets_connect (MT?.offset mt) j && MT?.hash_size mt = Path?.hash_size p && ([@inline_let] let k = split_offset (MT?.offset mt) k in [@inline_let] let j = split_offset (MT?.offset mt) j in // We need to add one since the first element is the hash to verify. V.size_of (Path?.hashes p) = 1ul + mt_path_length 0ul k j false) val mt_verify_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> k:uint64_t -> j:uint64_t -> mtr:HH.rid -> p:const_path_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let mtv0 = B.get h0 mt 0 in MT?.hash_size mtv0 = Ghost.reveal hsz /\ mt_safe h0 mt /\ path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HST.is_eternal_region (B.frameOf rt) /\ HH.disjoint (B.frameOf p) (B.frameOf rt) /\ HH.disjoint mtr (B.frameOf rt)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.const_mt_p -> k: EverCrypt.Helpers.uint64_t -> j: EverCrypt.Helpers.uint64_t -> mtr: FStar.Monotonic.HyperHeap.rid -> p: MerkleTree.Low.const_path_p -> rt: MerkleTree.Low.Datastructures.hash -> FStar.HyperStack.ST.ST Prims.bool
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.const_mt_p", "EverCrypt.Helpers.uint64_t", "FStar.Monotonic.HyperHeap.rid", "MerkleTree.Low.const_path_p", "MerkleTree.Low.Datastructures.hash", "FStar.Ghost.reveal", "MerkleTree.Low.mt_verify_pre_nst", "Prims.bool", "MerkleTree.Low.path", "LowStar.BufferOps.op_Bang_Star", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "MerkleTree.Low.merkle_tree", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.ConstBuffer.cast" ]
[]
false
true
false
false
false
let mt_verify_pre #hsz mt k j mtr p rt =
let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_verify_pre_nst mtv k j !*p rt
false
MerkleTree.Low.fst
MerkleTree.Low.mt_flush_to_modifies_rec_helper
val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs)))
val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs)))
let mt_flush_to_modifies_rec_helper #hsz lv hs h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 54, "end_line": 2195, "start_col": 0, "start_line": 2183 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after))))) #push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1" let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) #pop-options // For given a target index `k`, the number of elements (in the tree) `j`, // and a boolean flag (to check the existence of rightmost hashes), we can // calculate a required Merkle path length. // // `mt_path_length` is a postcondition of `mt_get_path`, and a precondition // of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`. private val mt_path_length_step: k:index_t -> j:index_t{k <= j} -> actd:bool -> Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd}) let mt_path_length_step k j actd = if j = 0ul then 0ul else (if k % 2ul = 0ul then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul) else 1ul) private inline_for_extraction val mt_path_length: lv:uint32_t{lv <= merkle_tree_size_lg} -> k:index_t -> j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} -> actd:bool -> Tot (l:uint32_t{ U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd && l <= 32ul - lv}) (decreases (U32.v j)) #push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1" let rec mt_path_length lv k j actd = if j = 0ul then 0ul else (let nactd = actd || (j % 2ul = 1ul) in mt_path_length_step k j actd + mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd) #pop-options val mt_get_path_length: mtr:HH.rid -> p:const_path_p -> HST.ST uint32_t (requires (fun h0 -> path_safe h0 mtr (CB.cast p))) (ensures (fun h0 _ h1 -> True)) let mt_get_path_length mtr p = let pd = !*(CB.cast p) in V.size_of (Path?.hashes pd) private inline_for_extraction val mt_make_path_step: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\ V.size_of (phashes h1 p) <= lv + 2ul /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_make_path_step (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2" let mt_make_path_step #hsz lv mtr hs rhs i j k p actd = let pth = !*p in let hh0 = HST.get () in let ofs = offset_of i in if k % 2ul = 1ul then begin hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs)))); assert(Path?.hash_size pth = hsz); mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs)) end else begin if k = j then () else if k + 1ul = j then (if actd then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv))); mt_path_insert mtr p (V.index rhs lv))) else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs); assert (HH.includes mtr (B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs)))); mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs))) end #pop-options private inline_for_extraction val mt_get_path_step_pre_nst: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:path -> i:uint32_t -> Tot bool let mt_get_path_step_pre_nst #hsz mtr p i = i < V.size_of (Path?.hashes p) val mt_get_path_step_pre: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST bool (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ mt_get_path_step_pre_nst #hsz mtr pv i))) (ensures (fun _ _ _ -> True)) let mt_get_path_step_pre #hsz mtr p i = let p = CB.cast p in mt_get_path_step_pre_nst #hsz mtr !*p i val mt_get_path_step: #hsz:Ghost.erased hash_size_t -> mtr:HH.rid -> p:const_path_p -> i:uint32_t -> HST.ST (hash #hsz) (requires (fun h0 -> path_safe h0 mtr (CB.cast p) /\ (let pv = B.get h0 (CB.cast p) 0 in Path?.hash_size pv = Ghost.reveal hsz /\ live h0 (Path?.hashes pv) /\ i < V.size_of (Path?.hashes pv)))) (ensures (fun h0 r h1 -> True )) let mt_get_path_step #hsz mtr p i = let pd = !*(CB.cast p) in V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i private val mt_get_path_: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> mtr:HH.rid -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} -> k:index_t{i <= k && k <= j} -> p:path_p -> actd:bool -> HST.ST unit (requires (fun h0 -> HH.includes mtr (V.frameOf hs) /\ HH.includes mtr (V.frameOf rhs) /\ RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ mt_safe_elts h0 lv hs i j /\ path_safe h0 mtr p /\ Path?.hash_size (B.get h0 p 0) = hsz /\ V.size_of (phashes h0 p) <= lv + 1ul)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length lv k j actd /\ // correctness (mt_safe_elts_spec h0 lv hs i j; (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in hsz = hsz0 /\ hsz = hsz1 /\ S.equal after (MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs) (U32.v i) (U32.v j) (U32.v k) before actd))))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2" let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd = let hh0 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; let ofs = offset_of i in if j = 0ul then () else (mt_make_path_step lv mtr hs rhs i j k p actd; let hh1 = HST.get () in mt_safe_elts_spec hh0 lv hs i j; assert (S.equal (lift_path hh1 mtr p) (MTH.mt_make_path_step (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd)); RV.rv_inv_preserved hs (path_loc p) hh0 hh1; RV.rv_inv_preserved rhs (path_loc p) hh0 hh1; RV.as_seq_preserved hs (path_loc p) hh0 hh1; RV.as_seq_preserved rhs (path_loc p) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1; assert (mt_safe_elts hh1 lv hs i j); mt_safe_elts_rec hh1 lv hs i j; mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul); mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p (if j % 2ul = 0ul then actd else true); let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv + 1) (RV.as_seq hh1 hs) (RV.as_seq hh1 rhs) (U32.v i / 2) (U32.v j / 2) (U32.v k / 2) (lift_path hh1 mtr p) (if U32.v j % 2 = 0 then actd else true))); assert (S.equal (lift_path hh2 mtr p) (MTH.mt_get_path_ (U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs) (U32.v i) (U32.v j) (U32.v k) (lift_path hh0 mtr p) actd))) #pop-options private inline_for_extraction val mt_get_path_pre_nst: mtv:merkle_tree -> idx:offset_t -> p:path -> root:(hash #(MT?.hash_size mtv)) -> Tot bool let mt_get_path_pre_nst mtv idx p root = offsets_connect (MT?.offset mtv) idx && Path?.hash_size p = MT?.hash_size mtv && ([@inline_let] let idx = split_offset (MT?.offset mtv) idx in MT?.i mtv <= idx && idx < MT?.j mtv && V.size_of (Path?.hashes p) = 0ul) val mt_get_path_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:const_path_p -> root:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in let p = CB.cast p in let dmt = B.get h0 mt 0 in let dp = B.get h0 p 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ Path?.hash_size dp = (Ghost.reveal hsz) /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun _ _ _ -> True)) let mt_get_path_pre #_ mt idx p root = let mt = CB.cast mt in let p = CB.cast p in let mtv = !*mt in mt_get_path_pre_nst mtv idx !*p root val mt_get_path_loc_union_helper: l1:loc -> l2:loc -> Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2) let mt_get_path_loc_union_helper l1 l2 = () // Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost // hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree // to the output path. #push-options "--z3rlimit 60" val mt_get_path: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> idx:offset_t -> p:path_p -> root:hash #hsz -> HST.ST index_t (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\ mt_safe h0 mt /\ path_safe h0 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h0 root /\ HH.disjoint (B.frameOf root) (B.frameOf mt) /\ HH.disjoint (B.frameOf root) (B.frameOf p))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in let idx = split_offset (MT?.offset mtv0) idx in MT?.hash_size mtv0 = Ghost.reveal hsz /\ MT?.hash_size mtv1 = Ghost.reveal hsz /\ Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\ Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\ // memory safety modifies (loc_union (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) h0 h1 /\ mt_safe h1 mt /\ path_safe h1 (B.frameOf mt) p /\ Rgl?.r_inv (hreg hsz) h1 root /\ V.size_of (phashes h1 p) == 1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\ // correctness (let sj, sp, srt = MTH.mt_get_path (mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in sj == U32.v (MT?.j mtv1) /\ S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\ srt == Rgl?.r_repr (hreg hsz) h1 root))) #pop-options #push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1" let mt_get_path #hsz mt idx p root = let ncmt = CB.cast mt in let mtframe = B.frameOf ncmt in let hh0 = HST.get () in mt_get_root mt root; let mtv = !*ncmt in let hsz = MT?.hash_size mtv in let hh1 = HST.get () in path_safe_init_preserved mtframe p (B.loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) hh0 hh1; assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) == (mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root)); assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty); let idx = split_offset (MT?.offset mtv) idx in let i = MT?.i mtv in let ofs = offset_of (MT?.i mtv) in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in assert (mt_safe_elts hh1 0ul hs i j); assert (V.size_of (V.get hh1 hs 0ul) == j - ofs); assert (idx < j); hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs); hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs); hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs); let ih = V.index (V.index hs 0ul) (idx - ofs) in mt_path_insert #hsz mtframe p ih; let hh2 = HST.get () in assert (S.equal (lift_path hh2 mtframe p) (MTH.path_insert (lift_path hh1 mtframe p) (S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs)))); Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2; mt_safe_preserved ncmt (path_loc p) hh1 hh2; mt_preserved ncmt (path_loc p) hh1 hh2; assert (V.size_of (phashes hh2 p) == 1ul); mt_get_path_ 0ul mtframe hs rhs i j idx p false; let hh3 = HST.get () in // memory safety mt_get_path_loc_union_helper (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p); Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3; mt_safe_preserved ncmt (path_loc p) hh2 hh3; mt_preserved ncmt (path_loc p) hh2 hh3; assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); assert (S.length (lift_path #hsz hh3 mtframe p) == S.length (lift_path #hsz hh2 mtframe p) + MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false); assert (modifies (loc_union (loc_union (mt_loc ncmt) (B.loc_all_regions_from false (B.frameOf root))) (path_loc p)) hh0 hh3); assert (mt_safe hh3 ncmt); assert (path_safe hh3 mtframe p); assert (Rgl?.r_inv (hreg hsz) hh3 root); assert (V.size_of (phashes hh3 p) == 1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false); // correctness mt_safe_elts_spec hh2 0ul hs i j; assert (S.equal (lift_path hh3 mtframe p) (MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs) (U32.v i) (U32.v j) (U32.v idx) (lift_path hh2 mtframe p) false)); assert (MTH.mt_get_path (mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) == (U32.v (MT?.j (B.get hh3 ncmt 0)), lift_path hh3 mtframe p, Rgl?.r_repr (hreg hsz) hh3 root)); j #pop-options /// Flushing private val mt_flush_to_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> h:HS.mem -> Lemma (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) == loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": 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": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: LowStar.Vector.uint32_t{lv < MerkleTree.Low.merkle_tree_size_lg} -> hs: MerkleTree.Low.Datastructures.hash_vv hsz {LowStar.Vector.size_of hs = MerkleTree.Low.merkle_tree_size_lg} -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (ensures LowStar.Monotonic.Buffer.loc_union (LowStar.Monotonic.Buffer.loc_union (LowStar.RVector.rs_loc_elem (MerkleTree.Low.Datastructures.hvreg hsz) (LowStar.Vector.as_seq h hs) (FStar.UInt32.v lv)) (LowStar.Vector.loc_vector_within hs lv (lv + 1ul))) (LowStar.Monotonic.Buffer.loc_union (LowStar.RVector.rv_loc_elems h hs (lv + 1ul) (LowStar.Vector.size_of hs)) (LowStar.Vector.loc_vector_within hs (lv + 1ul) (LowStar.Vector.size_of hs))) == LowStar.Monotonic.Buffer.loc_union (LowStar.RVector.rv_loc_elems h hs lv (LowStar.Vector.size_of hs)) (LowStar.Vector.loc_vector_within hs lv (LowStar.Vector.size_of hs)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "LowStar.Vector.uint32_t", "Prims.b2t", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "MerkleTree.Low.merkle_tree_size_lg", "MerkleTree.Low.Datastructures.hash_vv", "Prims.op_Equality", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash_vec", "FStar.Monotonic.HyperStack.mem", "MerkleTree.Low.loc_union_assoc_4", "LowStar.RVector.rs_loc_elem", "MerkleTree.Low.Datastructures.hvreg", "LowStar.Vector.as_seq", "FStar.UInt32.v", "LowStar.Vector.loc_vector_within", "FStar.Integers.op_Plus", "FStar.UInt32.__uint_to_t", "LowStar.RVector.rv_loc_elems", "Prims.unit", "Prims._assert", "Prims.eq2", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_union", "LowStar.RVector.rs_loc_elems_rec_inverse" ]
[]
true
false
true
false
false
let mt_flush_to_modifies_rec_helper #hsz lv hs h =
assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
false
MerkleTree.Low.fst
MerkleTree.Low.mt_path_insert
val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after)))))
val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after)))))
let mt_path_insert #hsz mtr p hp = let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv))
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 34, "end_line": 1739, "start_col": 0, "start_line": 1711 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ())) let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt #pop-options /// Destruction (free) val mt_free: mt:mt_p -> HST.ST unit (requires (fun h0 -> mt_safe h0 mt)) (ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1)) #push-options "--z3rlimit 100" let mt_free mt = let mtv = !*mt in RV.free (MT?.hs mtv); RV.free (MT?.rhs mtv); [@inline_let] let rg = hreg (MT?.hash_size mtv) in rg_free rg (MT?.mroot mtv); B.free mt #pop-options /// Insertion private val as_seq_sub_upd: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector #a #rst rg -> i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg -> Lemma (requires (RV.rv_inv h rv)) (ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v) (S.append (RV.as_seq_sub h rv 0ul i) (S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)))))) #push-options "--z3rlimit 20" let as_seq_sub_upd #a #rst #rg h rv i v = Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v; Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v; RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i); assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i)) (RV.as_seq_sub h rv 0ul i)); RV.as_seq_seq_slice rg h (V.as_seq h rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)); assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv))) (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))); assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v) #pop-options // `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying // and pushing its content to `hs[lv]`. For detailed insertion procedure, see // `insert_` and `mt_insert`. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1" private inline_for_extraction val hash_vv_insert_copy: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (V.frameOf hs) (B.frameOf v) /\ mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 v /\ V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\ V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\ mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\ RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) == RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.hashess_insert (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\ S.equal (S.index (RV.as_seq h1 hs) (U32.v lv)) (S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) (Rgl?.r_repr (hreg hsz) h0 v)))) let hash_vv_insert_copy #hsz lv i j hs v = let hh0 = HST.get () in mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j; /// 1) Insert an element at the level `lv`, where the new vector is not yet /// connected to `hs`. let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in let hh1 = HST.get () in // 1-0) Basic disjointness conditions V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv (fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2)); V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); // 1-1) For the `modifies` postcondition. assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1); // 1-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // 1-3) For `mt_safe_elts` assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet // 1-4) For the `rv_inv` postcondition RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv); RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs 0ul lv); RV.rs_loc_elems_elem_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v (V.size_of hs)) (U32.v lv + 1) (U32.v (V.size_of hs)) (U32.v lv); RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) (U32.v lv + 1) (U32.v (V.size_of hs)); RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs)); // assert (rv_itself_inv hh1 hs); // assert (elems_reg hh1 hs); // 1-5) Correctness assert (S.equal (RV.as_seq hh1 ihv) (S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v))); /// 2) Assign the updated vector to `hs` at the level `lv`. RV.assign hs lv ihv; let hh2 = HST.get () in // 2-1) For the `modifies` postcondition. assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2); // 2-2) Preservation Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-3) For `mt_safe_elts` assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2; // 2-4) Correctness RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1; RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1; assert (S.equal (RV.as_seq hh2 hs) (S.append (RV.as_seq_sub hh0 hs 0ul lv) (S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg)))); as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) #pop-options private val insert_index_helper_even: lv:uint32_t{lv < merkle_tree_size_lg} -> j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul <> 1ul)) (ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul)) let insert_index_helper_even lv j = () #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val insert_index_helper_odd: lv:uint32_t{lv < merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} -> Lemma (requires (j % 2ul = 1ul /\ j < uint32_32_max)) (ensures (U32.v j % 2 = 1 /\ U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\ (j + 1ul) / 2ul == j / 2ul + 1ul /\ j - offset_of i > 0ul)) let insert_index_helper_odd lv i j = () #pop-options private val loc_union_assoc_4: a:loc -> b:loc -> c:loc -> d:loc -> Lemma (loc_union (loc_union a b) (loc_union c d) == loc_union (loc_union a c) (loc_union b d)) let loc_union_assoc_4 a b c d = loc_union_assoc (loc_union a b) c d; loc_union_assoc a b c; loc_union_assoc a c b; loc_union_assoc (loc_union a c) b d private val insert_modifies_rec_helper: #hsz:hash_size_t -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> aloc:loc -> h:HS.mem -> Lemma (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc) (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc) == loc_union (loc_union (RV.rv_loc_elems h hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) aloc) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let insert_modifies_rec_helper #hsz lv hs aloc h = assert (V.loc_vector_within hs lv (V.size_of hs) == loc_union (V.loc_vector_within hs lv (lv + 1ul)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))); RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs)); assert (RV.rv_loc_elems h hs lv (V.size_of hs) == loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))); // Applying some association rules... loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) aloc (loc_union (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc); loc_union_assoc (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc; loc_union_assoc (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (loc_union (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc; loc_union_assoc_4 (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) #pop-options private val insert_modifies_union_loc_weakening: l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (modifies l1 h0 h1)) (ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1)) let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 = B.loc_includes_union_l l1 l2 l1; B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2) private val insert_snoc_last_helper: #a:Type -> s:S.seq a{S.length s > 0} -> v:a -> Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s) let insert_snoc_last_helper #a s v = () private val rv_inv_rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (RV.rv_inv h rv)) (ensures (RV.rv_elems_reg h rv i j)) let rv_inv_rv_elems_reg #a #rst #rg h rv i j = () // `insert_` recursively inserts proper hashes to each level `lv` by // accumulating a compressed hash. For example, if there are three leaf elements // in the tree, `insert_` will change `hs` as follow: // (`hij` is a compressed hash from `hi` to `hj`) // // BEFORE INSERTION AFTER INSERTION // lv // 0 h0 h1 h2 ====> h0 h1 h2 h3 // 1 h01 h01 h23 // 2 h03 // private val insert_: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv < merkle_tree_size_lg} -> i:Ghost.erased index_t -> j:index_t{ Ghost.reveal i <= j && U32.v j < pow2 (32 - U32.v lv) - 1 && j < uint32_32_max} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> acc:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (V.frameOf hs) (B.frameOf acc) /\ mt_safe_elts h0 lv hs (Ghost.reveal i) j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (loc_union (RV.rv_loc_elems h0 hs lv (V.size_of hs)) (V.loc_vector_within hs lv (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 hs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\ // correctness (mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j; S.equal (RV.as_seq h1 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc))))) (decreases (U32.v j)) #push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun = let hh0 = HST.get () in hash_vv_insert_copy lv i j hs acc; let hh1 = HST.get () in // Base conditions V.loc_vector_within_included hs lv (lv + 1ul); V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs); V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs); assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)); if j % 2ul = 1ul then (insert_index_helper_odd lv (Ghost.reveal i) j; assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0); let lvhs = V.index hs lv in assert (U32.v (V.size_of lvhs) == S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1); assert (V.size_of lvhs > 1ul); /// 3) Update the accumulator `acc`. hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul); assert (Rgl?.r_inv (hreg hsz) hh1 acc); hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc; let hh2 = HST.get () in // 3-1) For the `modifies` postcondition assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2); assert (modifies (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh2); // 3-2) Preservation RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; assert (RV.rv_inv hh2 hs); assert (Rgl?.r_inv (hreg hsz) hh2 acc); // 3-3) For `mt_safe_elts` V.get_preserved hs lv (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved mt_safe_elts_preserved (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved // 3-4) Correctness insert_snoc_last_helper (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_` ((Ghost.reveal hash_spec) (S.last (S.index (RV.as_seq hh0 hs) (U32.v lv))) (Rgl?.r_repr (hreg hsz) hh0 acc))); /// 4) Recursion insert_ (lv + 1ul) (Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul) hs acc hash_fun; let hh3 = HST.get () in // 4-0) Memory safety brought from the postcondition of the recursion assert (RV.rv_inv hh3 hs); assert (Rgl?.r_inv (hreg hsz) hh3 acc); assert (modifies (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3); assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh3); // 4-1) For `mt_safe_elts` rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs); RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))); assert (loc_disjoint (V.loc_vector_within hs lv (lv + 1ul)) (B.loc_all_regions_from false (B.frameOf acc))); V.get_preserved hs lv (loc_union (loc_union (V.loc_vector_within hs (lv + 1ul) (V.size_of hs)) (RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh2 hh3; assert (V.size_of (V.get hh3 hs lv) == j + 1ul - offset_of (Ghost.reveal i)); // head preserved assert (mt_safe_elts hh3 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul)); // 4-2) Correctness mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2) (RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc))); mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh3 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))) else (insert_index_helper_even lv j; // memory safety assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul)); mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul); assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul)); assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) hh0 hh1); insert_modifies_union_loc_weakening (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc)) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc))) hh0 hh1; // correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc); assert (S.equal (RV.as_seq hh1 hs) (MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc)))); /// 5) Proving the postcondition after recursion let hh4 = HST.get () in // 5-1) For the `modifies` postcondition. assert (modifies (loc_union (loc_union (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) (V.loc_vector_within hs lv (lv + 1ul))) (B.loc_all_regions_from false (B.frameOf acc))) (loc_union (loc_union (RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs)) (V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf acc)))) hh0 hh4); insert_modifies_rec_helper lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0; // 5-2) For `mt_safe_elts` assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul)); // 5-3) Preservation assert (RV.rv_inv hh4 hs); assert (Rgl?.r_inv (hreg hsz) hh4 acc); // 5-4) Correctness mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j; assert (S.equal (RV.as_seq hh4 hs) (MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j) (RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED #pop-options private inline_for_extraction val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul) val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz)) (ensures (fun _ _ _ -> True)) let mt_insert_pre #hsz mt v = let mt = !*(CB.cast mt) in assert (MT?.hash_size mt == (MT?.hash_size mt)); mt_insert_pre_nst mt v // `mt_insert` inserts a hash to a Merkle tree. Note that this operation // manipulates the content in `v`, since it uses `v` as an accumulator during // insertion. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" val mt_insert: hsz:Ghost.erased hash_size_t -> mt:mt_p -> v:hash #hsz -> HST.ST unit (requires (fun h0 -> let dmt = B.get h0 mt 0 in mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 v /\ HH.disjoint (B.frameOf mt) (B.frameOf v) /\ MT?.hash_size dmt = Ghost.reveal hsz /\ mt_insert_pre_nst dmt v)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf v))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\ mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v))) #pop-options #push-options "--z3rlimit 40" let mt_insert hsz mt v = let hh0 = HST.get () in let mtv = !*mt in let hs = MT?.hs mtv in let hsz = MT?.hash_size mtv in insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv); let hh1 = HST.get () in RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs); V.loc_vector_within_included hs 0ul (V.size_of hs); RV.rv_inv_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; RV.as_seq_preserved (MT?.rhs mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (loc_union (loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))) (B.loc_all_regions_from false (B.frameOf v))) hh0 hh1; mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (MT?.hs mtv) false // `rhs` is always deprecated right after an insertion. (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv); let hh2 = HST.get () in RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2; RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2; Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2; mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt) hh1 hh2 #pop-options // `mt_create` initiates a Merkle tree with a given initial hash `init`. // A valid Merkle tree should contain at least one element. val mt_create_custom: hsz:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p (requires (fun h0 -> Rgl?.r_inv (hreg hsz) h0 init /\ HH.disjoint r (B.frameOf init))) (ensures (fun h0 mt h1 -> // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\ mt_safe h1 mt /\ // correctness MT?.hash_size (B.get h1 mt 0) = hsz /\ mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init))) #push-options "--z3rlimit 40" let mt_create_custom hsz hash_spec r init hash_fun = let hh0 = HST.get () in let mt = create_empty_mt hsz hash_spec hash_fun r in mt_insert hsz mt init; let hh2 = HST.get () in mt #pop-options /// Construction and Destruction of paths // Since each element pointer in `path` is from the target Merkle tree and // each element has different location in `MT?.hs` (thus different region id), // we cannot use the regionality property for `path`s. Hence here we manually // define invariants and representation. noeq type path = | Path: hash_size:hash_size_t -> hashes:V.vector (hash #hash_size) -> path type path_p = B.pointer path type const_path_p = const_pointer path private let phashes (h:HS.mem) (p:path_p) : GTot (V.vector (hash #(Path?.hash_size (B.get h p 0)))) = Path?.hashes (B.get h p 0) // Memory safety of a path as an invariant inline_for_extraction noextract val path_safe: h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0 let path_safe h mtr p = B.live h p /\ B.freeable p /\ V.live h (phashes h p) /\ V.freeable (phashes h p) /\ HST.is_eternal_region (V.frameOf (phashes h p)) /\ (let hsz = Path?.hash_size (B.get h p 0) in V.forall_all h (phashes h p) (fun hp -> Rgl?.r_inv (hreg hsz) h hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\ HH.disjoint mtr (B.frameOf p)) val path_loc: path_p -> GTot loc let path_loc p = B.loc_all_regions_from false (B.frameOf p) val lift_path_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{ i <= j /\ j <= S.length hs /\ V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j) let rec lift_path_ #hsz h hs i j = if i = j then S.empty else (S.snoc (lift_path_ h hs i (j - 1)) (Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1)))) // Representation of a path val lift_path: #hsz:hash_size_t -> h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} -> GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))}) let lift_path #hsz h mtr p = lift_path_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) val lift_path_index_: #hsz:hash_size_t -> h:HS.mem -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> k:nat{i <= k && k < j} -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) == S.index (lift_path_ h hs i j) (k - i))) (decreases j) [SMTPat (S.index (lift_path_ h hs i j) (k - i))] #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec lift_path_index_ #hsz h hs i j k = if i = j then () else if k = j - 1 then () else lift_path_index_ #hsz h hs i (j - 1) k #pop-options val lift_path_index: h:HS.mem -> mtr:HH.rid -> p:path_p -> i:uint32_t -> Lemma (requires (path_safe h mtr p /\ i < V.size_of (phashes h p))) (ensures (let hsz = Path?.hash_size (B.get h p 0) in Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) == S.index (lift_path #(hsz) h mtr p) (U32.v i))) let lift_path_index h mtr p i = lift_path_index_ h (V.as_seq h (phashes h p)) 0 (S.length (V.as_seq h (phashes h p))) (U32.v i) val lift_path_eq: #hsz:hash_size_t -> h:HS.mem -> hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) -> i:nat -> j:nat -> Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\ S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\ V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\ V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp))) (ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j))) let lift_path_eq #hsz h hs1 hs2 i j = assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs1 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs1 k)); assert (forall (k:nat{i <= k && k < j}). S.index (lift_path_ h hs2 i j) (k - i) == Rgl?.r_repr (hreg hsz) h (S.index hs2 k)); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs1 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i))); assert (forall (k:nat{k < j - i}). S.index (lift_path_ h hs2 i j) k == Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i))); assert (forall (k:nat{k < j - i}). S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k); assert (forall (k:nat{i <= k && k < j}). S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i)) private val path_safe_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h1 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)))) (decreases j) let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1; path_safe_preserved_ mtr hs i (j - 1) dl h0 h1) val path_safe_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p)) let path_safe_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_safe_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val path_safe_init_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ V.size_of (phashes h0 p) = 0ul /\ B.loc_disjoint dl (path_loc p) /\ modifies dl h0 h1)) (ensures (path_safe h1 mtr p /\ V.size_of (phashes h1 p) = 0ul)) let path_safe_init_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))) val path_preserved_: #hsz:hash_size_t -> mtr:HH.rid -> hs:S.seq (hash #hsz) -> i:nat -> j:nat{i <= j && j <= S.length hs} -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\ HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved_ mtr hs i j dl h0 h1; S.equal (lift_path_ h0 hs i j) (lift_path_ h1 hs i j))) (decreases j) #push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec path_preserved_ #hsz mtr hs i j dl h0 h1 = if i = j then () else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1; path_preserved_ mtr hs i (j - 1) dl h0 h1; assert (loc_includes (B.loc_all_regions_from false mtr) (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) (S.index hs (j - 1))))); Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1) #pop-options val path_preserved: mtr:HH.rid -> p:path_p -> dl:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (path_safe h0 mtr p /\ loc_disjoint dl (path_loc p) /\ loc_disjoint dl (B.loc_all_regions_from false mtr) /\ modifies dl h0 h1)) (ensures (path_safe_preserved mtr p dl h0 h1; let hsz0 = (Path?.hash_size (B.get h0 p 0)) in let hsz1 = (Path?.hash_size (B.get h1 p 0)) in let b:MTH.path = lift_path #hsz0 h0 mtr p in let a:MTH.path = lift_path #hsz1 h1 mtr p in hsz0 = hsz1 /\ S.equal b a)) let path_preserved mtr p dl h0 h1 = assert (loc_includes (path_loc p) (B.loc_buffer p)); assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p))); path_preserved_ mtr (V.as_seq h0 (phashes h0 p)) 0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1 val init_path: hsz:hash_size_t -> mtr:HH.rid -> r:HST.erid -> HST.ST path_p (requires (fun h0 -> HH.disjoint mtr r)) (ensures (fun h0 p h1 -> // memory safety path_safe h1 mtr p /\ // correctness Path?.hash_size (B.get h1 p 0) = hsz /\ S.equal (lift_path #hsz h1 mtr p) S.empty)) let init_path hsz mtr r = let nrid = HST.new_region r in (B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul) val clear_path: mtr:HH.rid -> p:path_p -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p)) (ensures (fun h0 _ h1 -> // memory safety path_safe h1 mtr p /\ // correctness V.size_of (phashes h1 p) = 0ul /\ S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty)) let clear_path mtr p = let pv = !*p in p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv)) val free_path: p:path_p -> HST.ST unit (requires (fun h0 -> B.live h0 p /\ B.freeable p /\ V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\ HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p))) (ensures (fun h0 _ h1 -> modifies (path_loc p) h0 h1)) let free_path p = let pv = !*p in V.free (Path?.hashes pv); B.free p /// Getting the Merkle root and path // Construct "rightmost hashes" for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. private val construct_rhs: #hsz:hash_size_t -> #hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} -> i:index_t -> j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} -> acc:hash #hsz -> actd:bool -> hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) -> HST.ST unit (requires (fun h0 -> RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\ HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\ Rgl?.r_inv (hreg hsz) h0 acc /\ HH.disjoint (B.frameOf acc) (V.frameOf hs) /\ HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\ mt_safe_elts #hsz h0 lv hs i j)) (ensures (fun h0 _ h1 -> // memory safety modifies (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf acc))) h0 h1 /\ RV.rv_inv h1 rhs /\ Rgl?.r_inv (hreg hsz) h1 acc /\ // correctness (mt_safe_elts_spec #hsz h0 lv hs i j; MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) h0 hs) (Rgl?.r_repr (hvreg hsz) h0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) h0 acc) actd == (Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc) ))) (decreases (U32.v j)) #push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun = let hh0 = HST.get () in if j = 0ul then begin assert (RV.rv_inv hh0 hs); assert (mt_safe_elts #hsz hh0 lv hs i j); mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul; assert (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq hh0 hs) (U32.v i) (U32.v j)); let hh1 = HST.get() in assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else let ofs = offset_of i in begin (if j % 2ul = 0ul then begin Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1); mt_safe_elts_rec #hsz hh0 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun; let hh1 = HST.get () in // correctness mt_safe_elts_spec #hsz hh0 lv hs i j; MTH.construct_rhs_even #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc)) end else begin if actd then begin RV.assign_copy (hcpy hsz) rhs lv acc; let hh1 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) acc (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; RV.rv_inv_preserved (V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1; mt_safe_elts_head hh1 lv hs i j; hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs); // correctness assert (S.equal (RV.as_seq hh1 rhs) (S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc))); hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc; let hh2 = HST.get () in // memory safety mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh2 acc == (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc)) end else begin mt_safe_elts_head hh0 lv hs i j; hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs); hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc); Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc; let hh1 = HST.get () in // memory safety V.loc_vector_within_included hs lv (V.size_of hs); mt_safe_elts_preserved lv hs i j (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1; // correctness hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs); assert (Rgl?.r_repr (hreg hsz) hh1 acc == S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) end; let hh3 = HST.get () in assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs)); assert (S.equal (RV.as_seq hh3 rhs) (if actd then S.upd (RV.as_seq hh0 rhs) (U32.v lv) (Rgl?.r_repr (hreg hsz) hh0 acc) else RV.as_seq hh0 rhs)); assert (Rgl?.r_repr (hreg hsz) hh3 acc == (if actd then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs)) (Rgl?.r_repr (hreg hsz) hh0 acc) else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv)) (U32.v j - 1 - U32.v ofs))); mt_safe_elts_rec hh3 lv hs i j; construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun; let hh4 = HST.get () in mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul); assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv + 1) (Rgl?.r_repr (hvvreg hsz) hh3 hs) (Rgl?.r_repr (hvreg hsz) hh3 rhs) (U32.v i / 2) (U32.v j / 2) (Rgl?.r_repr (hreg hsz) hh3 acc) true == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)); mt_safe_elts_spec hh0 lv hs i j; MTH.construct_rhs_odd #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd; assert (MTH.construct_rhs #(U32.v hsz) #hash_spec (U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd == (Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc)) end) end #pop-options private inline_for_extraction val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool let mt_get_root_pre_nst mtv rt = true val mt_get_root_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST bool (requires (fun h0 -> let mt = CB.cast mt in MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun _ _ _ -> True)) let mt_get_root_pre #hsz mt rt = let mt = CB.cast mt in let mt = !*mt in let hsz = MT?.hash_size mt in assert (MT?.hash_size mt = hsz); mt_get_root_pre_nst mt rt // `mt_get_root` returns the Merkle root. If it's already calculated with // up-to-date hashes, the root is returned immediately. Otherwise it calls // `construct_rhs` to build rightmost hashes and to calculate the Merkle root // as well. val mt_get_root: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> rt:hash #hsz -> HST.ST unit (requires (fun h0 -> let mt = CB.cast mt in let dmt = B.get h0 mt 0 in MT?.hash_size dmt = (Ghost.reveal hsz) /\ mt_get_root_pre_nst dmt rt /\ mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\ HH.disjoint (B.frameOf mt) (B.frameOf rt))) (ensures (fun h0 _ h1 -> let mt = CB.cast mt in // memory safety modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf rt))) h0 h1 /\ mt_safe h1 mt /\ (let mtv0 = B.get h0 mt 0 in let mtv1 = B.get h1 mt 0 in MT?.hash_size mtv0 = (Ghost.reveal hsz) /\ MT?.hash_size mtv1 = (Ghost.reveal hsz) /\ MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\ MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\ MT?.offset mtv1 == MT?.offset mtv0 /\ MT?.rhs_ok mtv1 = true /\ Rgl?.r_inv (hreg hsz) h1 rt /\ // correctness MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) == (mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt)))) #push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1" let mt_get_root #hsz mt rt = let mt = CB.cast mt in let hh0 = HST.get () in let mtv = !*mt in let prefix = MT?.offset mtv in let i = MT?.i mtv in let j = MT?.j mtv in let hs = MT?.hs mtv in let rhs = MT?.rhs mtv in let mroot = MT?.mroot mtv in let hash_size = MT?.hash_size mtv in let hash_spec = MT?.hash_spec mtv in let hash_fun = MT?.hash_fun mtv in if MT?.rhs_ok mtv then begin Cpy?.copy (hcpy hash_size) hash_size mroot rt; let hh1 = HST.get () in mt_safe_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; mt_preserved mt (B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1; MTH.mt_get_root_rhs_ok_true (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt)) end else begin construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in // memory safety assert (RV.rv_inv hh1 rhs); assert (Rgl?.r_inv (hreg hsz) hh1 rt); assert (B.live hh1 mt); RV.rv_inv_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; RV.as_seq_preserved hs (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved 0ul hs i j (loc_union (RV.loc_rvector rhs) (B.loc_all_regions_from false (B.frameOf rt))) hh0 hh1; // correctness mt_safe_elts_spec hh0 0ul hs i j; assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0 (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs) (U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 rt) false == (Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt)); Cpy?.copy (hcpy hash_size) hash_size rt mroot; let hh2 = HST.get () in // memory safety RV.rv_inv_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.rv_inv_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved hs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; RV.as_seq_preserved rhs (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; B.modifies_buffer_elim rt (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; mt_safe_elts_preserved 0ul hs i j (B.loc_all_regions_from false (B.frameOf mroot)) hh1 hh2; // correctness assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt); mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun; let hh3 = HST.get () in // memory safety Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3; RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3; RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3; Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3; mt_safe_elts_preserved 0ul hs i j (B.loc_buffer mt) hh2 hh3; assert (mt_safe hh3 mt); // correctness MTH.mt_get_root_rhs_ok_false (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (MTH.MT #(U32.v hash_size) (U32.v i) (U32.v j) (RV.as_seq hh0 hs) true (RV.as_seq hh1 rhs) (Rgl?.r_repr (hreg hsz) hh1 rt) hash_spec, Rgl?.r_repr (hreg hsz) hh1 rt)); assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) == (mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt)) end #pop-options inline_for_extraction val mt_path_insert: #hsz:hash_size_t -> mtr:HH.rid -> p:path_p -> hp:hash #hsz -> HST.ST unit (requires (fun h0 -> path_safe h0 mtr p /\ not (V.is_full (phashes h0 p)) /\ Rgl?.r_inv (hreg hsz) h0 hp /\ HH.disjoint mtr (B.frameOf p) /\ HH.includes mtr (B.frameOf hp) /\ Path?.hash_size (B.get h0 p 0) = hsz)) (ensures (fun h0 _ h1 -> // memory safety modifies (path_loc p) h0 h1 /\ path_safe h1 mtr p /\ // correctness (let hsz0 = Path?.hash_size (B.get h0 p 0) in let hsz1 = Path?.hash_size (B.get h1 p 0) in (let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\ hsz = hsz0 /\ hsz = hsz1 /\ (let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in S.equal hspec after)))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": 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": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mtr: FStar.Monotonic.HyperHeap.rid -> p: MerkleTree.Low.path_p -> hp: MerkleTree.Low.Datastructures.hash -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Monotonic.HyperHeap.rid", "MerkleTree.Low.path_p", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.lift_path_eq", "MerkleTree.Low.__proj__Path__item__hash_size", "FStar.Seq.Properties.snoc", "LowStar.Vector.as_seq", "FStar.Seq.Base.length", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "MerkleTree.New.High.hash", "FStar.UInt32.v", "MerkleTree.Low.lift_path", "MerkleTree.Low.lift_path_", "LowStar.Regional.__proj__Rgl__item__r_sep", "MerkleTree.Low.Datastructures.hreg", "LowStar.Monotonic.Buffer.loc_region_only", "LowStar.Monotonic.Buffer.frameOf", "MerkleTree.Low.path", "LowStar.Buffer.trivial_preorder", "MerkleTree.Low.path_preserved_", "MerkleTree.Low.path_safe_preserved_", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.BufferOps.op_Star_Equals", "MerkleTree.Low.Path", "LowStar.Monotonic.Buffer.loc_all_regions_from", "LowStar.Vector.frameOf", "LowStar.Vector.vector", "LowStar.Vector.insert", "MerkleTree.Low.__proj__Path__item__hashes", "LowStar.BufferOps.op_Bang_Star" ]
[]
false
true
false
false
false
let mt_path_insert #hsz mtr p hp =
let pth = !*p in let pv = Path?.hashes pth in let hh0 = HST.get () in let ipv = V.insert pv hp in let hh1 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; path_preserved_ mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv)) (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; Rgl?.r_sep (hreg hsz) hp (B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1; p *= Path hsz ipv; let hh2 = HST.get () in path_safe_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; path_preserved_ mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv)) (B.loc_region_only false (B.frameOf p)) hh1 hh2; Rgl?.r_sep (hreg hsz) hp (B.loc_region_only false (B.frameOf p)) hh1 hh2; assert (S.equal (lift_path hh2 mtr p) (lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp) 0 (S.length (V.as_seq hh1 ipv)))); lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv))
false
Hacl.Impl.Load56.fst
Hacl.Impl.Load56.lemma_nat_from_bytes_le_append
val lemma_nat_from_bytes_le_append (k1 k2: bytes) : Lemma (requires Seq.length k1 + Seq.length k2 <= max_size_t) (ensures nat_from_bytes_le (Seq.append k1 k2) == nat_from_bytes_le k1 + pow2 (Seq.length k1 * 8) * nat_from_bytes_le k2)
val lemma_nat_from_bytes_le_append (k1 k2: bytes) : Lemma (requires Seq.length k1 + Seq.length k2 <= max_size_t) (ensures nat_from_bytes_le (Seq.append k1 k2) == nat_from_bytes_le k1 + pow2 (Seq.length k1 * 8) * nat_from_bytes_le k2)
let lemma_nat_from_bytes_le_append (k1 k2:bytes) : Lemma (requires Seq.length k1 + Seq.length k2 <= max_size_t) (ensures nat_from_bytes_le (Seq.append k1 k2) == nat_from_bytes_le k1 + pow2 (Seq.length k1 * 8) * nat_from_bytes_le k2) = let k = Seq.append k1 k2 in let n = Seq.length k1 + Seq.length k2 in nat_from_intseq_le_slice_lemma #U8 #SEC #n k (Seq.length k1); assert (k1 `Seq.equal` Seq.slice k 0 (Seq.length k1)); assert (k2 `Seq.equal` Seq.slice k (Seq.length k1) n)
{ "file_name": "code/ed25519/Hacl.Impl.Load56.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 70, "start_col": 0, "start_line": 62 }
module Hacl.Impl.Load56 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.ByteSequence open Lib.Buffer open Lib.ByteBuffer module F56 = Hacl.Impl.BignumQ.Mul module S56 = Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val hload56_le: b:lbuffer uint8 64ul -> off:size_t{v off <= 56} -> Stack uint64 (requires fun h -> live h b) (ensures fun h0 z h1 -> h0 == h1 /\ v z < 0x100000000000000 /\ v z == nat_from_bytes_le (Seq.slice (as_seq h0 b) (v off) (v off + 7)) ) let hload56_le b off = let h0 = ST.get() in let b8 = sub b off 8ul in let z = uint_from_bytes_le b8 in let z' = z &. u64 0xffffffffffffff in assert_norm (0xffffffffffffff == pow2 56 - 1); assert_norm (0x100000000000000 == pow2 56 ); calc (==) { v z' <: nat; (==) { } v (z &. u64 0xffffffffffffff); (==) { logand_spec z (u64 0xffffffffffffff) } v z `logand_v` 0xffffffffffffff; (==) { assert_norm(pow2 56 - 1 == 0xffffffffffffff); UInt.logand_mask (UInt.to_uint_t 64 (v z)) 56 } (v z % pow2 56); (==) { lemma_reveal_uint_to_bytes_le #U64 #SEC (as_seq h0 b8) } nat_from_bytes_le (as_seq h0 b8) % pow2 56; (==) { nat_from_intseq_le_slice_lemma (as_seq h0 b8) 7 } (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) + pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) % pow2 56; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7)) (pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56); FStar.Math.Lemmas.swap_mul (pow2 (7 * 8)) (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)); FStar.Math.Lemmas.cancel_mul_mod (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56) } nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) <: nat; }; assert (Seq.equal (Seq.slice (as_seq h0 b) (v off) (v off + 7)) (Seq.slice (as_seq h0 b8) 0 7)); z'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "Hacl.Impl.BignumQ.Mul.fsti.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Load56.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": "S56" }, { "abbrev": true, "full_module": "Hacl.Impl.BignumQ.Mul", "short_module": "F56" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k1: Lib.ByteSequence.bytes -> k2: Lib.ByteSequence.bytes -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length k1 + FStar.Seq.Base.length k2 <= Lib.IntTypes.max_size_t) (ensures Lib.ByteSequence.nat_from_bytes_le (FStar.Seq.Base.append k1 k2) == Lib.ByteSequence.nat_from_bytes_le k1 + Prims.pow2 (FStar.Seq.Base.length k1 * 8) * Lib.ByteSequence.nat_from_bytes_le k2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.ByteSequence.bytes", "Prims._assert", "FStar.Seq.Base.equal", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.unit", "Lib.ByteSequence.nat_from_intseq_le_slice_lemma", "Prims.int", "Prims.op_Addition", "FStar.Seq.Base.seq", "Lib.IntTypes.int_t", "FStar.Seq.Base.append", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Prims.squash", "Prims.eq2", "Lib.ByteSequence.nat_from_bytes_le", "FStar.Mul.op_Star", "Prims.pow2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_nat_from_bytes_le_append (k1 k2: bytes) : Lemma (requires Seq.length k1 + Seq.length k2 <= max_size_t) (ensures nat_from_bytes_le (Seq.append k1 k2) == nat_from_bytes_le k1 + pow2 (Seq.length k1 * 8) * nat_from_bytes_le k2) =
let k = Seq.append k1 k2 in let n = Seq.length k1 + Seq.length k2 in nat_from_intseq_le_slice_lemma #U8 #SEC #n k (Seq.length k1); assert (k1 `Seq.equal` (Seq.slice k 0 (Seq.length k1))); assert (k2 `Seq.equal` (Seq.slice k (Seq.length k1) n))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.uzero
val uzero : FStar.Stubs.Reflection.Types.universe
let uzero = R.pack_universe (R.Uv_Zero)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 116, "start_col": 0, "start_line": 116 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.universe
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_universe", "FStar.Stubs.Reflection.V2.Data.Uv_Zero" ]
[]
false
false
false
true
false
let uzero =
R.pack_universe (R.Uv_Zero)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.true_tm
val true_tm : FStar.Stubs.Reflection.Types.term
let true_tm = R.pack_ln (R.Tv_Const (R.C_True))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 87, "start_col": 0, "start_line": 87 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_Const", "FStar.Stubs.Reflection.V2.Data.C_True" ]
[]
false
false
false
true
false
let true_tm =
R.pack_ln (R.Tv_Const (R.C_True))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_stt_ghost_admit
val mk_stt_ghost_admit (u: R.universe) (t pre post: R.term) : R.term
val mk_stt_ghost_admit (u: R.universe) (t pre post: R.term) : R.term
let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 155, "start_col": 0, "start_line": 150 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u84: FStar.Stubs.Reflection.Types.universe -> t: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.stt_ghost_admit_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_stt_ghost_admit (u: R.universe) (t pre post: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_tuple2
val mk_tuple2 (u1 u2: R.universe) (a1 a2: R.term) : R.term
val mk_tuple2 (u1 u2: R.universe) (a1 a2: R.term) : R.term
let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 71, "start_col": 0, "start_line": 67 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u1: FStar.Stubs.Reflection.Types.universe -> u2: FStar.Stubs.Reflection.Types.universe -> a1: FStar.Stubs.Reflection.Types.term -> a2: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.tuple2_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_tuple2 (u1 u2: R.universe) (a1 a2: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_atomic_tm
val stt_atomic_tm : FStar.Stubs.Reflection.Types.term
let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 175, "start_col": 0, "start_line": 175 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.stt_atomic_fv" ]
[]
false
false
false
true
false
let stt_atomic_tm =
R.pack_ln (R.Tv_FVar stt_atomic_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_ghost_admit_lid
val stt_ghost_admit_lid : Prims.list Prims.string
let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 65, "end_line": 149, "start_col": 0, "start_line": 149 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_ghost_admit_lid =
mk_pulse_lib_core_lid "stt_ghost_admit"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.inames_lid
val inames_lid : Prims.list Prims.string
let inames_lid = mk_pulse_lib_core_lid "inames"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 92, "start_col": 0, "start_line": 92 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let inames_lid =
mk_pulse_lib_core_lid "inames"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_pulse_lib_forall_lid
val mk_pulse_lib_forall_lid : s: Prims.string -> Prims.list Prims.string
let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 52, "end_line": 105, "start_col": 0, "start_line": 105 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "FStar.List.Tot.Base.op_At", "Pulse.Reflection.Util.pulse_lib_forall", "Prims.Cons", "Prims.Nil", "Prims.list" ]
[]
false
false
false
true
false
let mk_pulse_lib_forall_lid s =
pulse_lib_forall @ [s]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_stt_admit
val mk_stt_admit (u: R.universe) (t pre post: R.term) : R.term
val mk_stt_admit (u: R.universe) (t pre post: R.term) : R.term
let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 139, "start_col": 0, "start_line": 134 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u68: FStar.Stubs.Reflection.Types.universe -> t: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.stt_admit_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_stt_admit (u: R.universe) (t pre post: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.remove_inv_lid
val remove_inv_lid : Prims.list Prims.string
let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 160, "start_col": 0, "start_line": 160 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let remove_inv_lid =
mk_pulse_lib_core_lid "remove_inv"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_admit_lid
val stt_admit_lid : Prims.list Prims.string
let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 133, "start_col": 0, "start_line": 133 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_admit_lid =
mk_pulse_lib_core_lid "stt_admit"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.star_lid
val star_lid : Prims.list Prims.string
let star_lid = mk_pulse_lib_core_lid "op_Star_Star"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 94, "start_col": 0, "start_line": 94 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let star_lid =
mk_pulse_lib_core_lid "op_Star_Star"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.emp_lid
val emp_lid : Prims.list Prims.string
let emp_lid = mk_pulse_lib_core_lid "emp"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 91, "start_col": 0, "start_line": 91 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let emp_lid =
mk_pulse_lib_core_lid "emp"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_pulse_lib_reference_lid
val mk_pulse_lib_reference_lid : s: Prims.string -> Prims.list Prims.string
let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 58, "end_line": 119, "start_col": 0, "start_line": 119 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "FStar.List.Tot.Base.op_At", "Pulse.Reflection.Util.pulse_lib_reference", "Prims.Cons", "Prims.Nil", "Prims.list" ]
[]
false
false
false
true
false
let mk_pulse_lib_reference_lid s =
pulse_lib_reference @ [s]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_fv
val stt_fv : FStar.Stubs.Reflection.Types.fv
let stt_fv = R.pack_fv stt_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 165, "start_col": 0, "start_line": 165 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.stt_lid" ]
[]
false
false
false
true
false
let stt_fv =
R.pack_fv stt_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_squash
val mk_squash (u: R.universe) (ty: R.term) : R.term
val mk_squash (u: R.universe) (ty: R.term) : R.term
let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 124, "start_col": 0, "start_line": 121 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u52: FStar.Stubs.Reflection.Types.universe -> ty: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Reflection.Const.squash_qn", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_squash (u: R.universe) (ty: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.false_tm
val false_tm : FStar.Stubs.Reflection.Types.term
let false_tm = R.pack_ln (R.Tv_Const (R.C_False))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 88, "start_col": 0, "start_line": 88 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_Const", "FStar.Stubs.Reflection.V2.Data.C_False" ]
[]
false
false
false
true
false
let false_tm =
R.pack_ln (R.Tv_Const (R.C_False))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_unobservable_tm
val stt_unobservable_tm : FStar.Stubs.Reflection.Types.term
let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 67, "end_line": 178, "start_col": 0, "start_line": 178 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.stt_unobservable_fv" ]
[]
false
false
false
true
false
let stt_unobservable_tm =
R.pack_ln (R.Tv_FVar stt_unobservable_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.all_inames_lid
val all_inames_lid : Prims.list Prims.string
let all_inames_lid = mk_pulse_lib_core_lid "all_inames"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 158, "start_col": 0, "start_line": 158 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let all_inames_lid =
mk_pulse_lib_core_lid "all_inames"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_unobservable_lid
val stt_unobservable_lid : Prims.list Prims.string
let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 67, "end_line": 176, "start_col": 0, "start_line": 176 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_unobservable_lid =
mk_pulse_lib_core_lid "stt_unobservable"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_stt_atomic_admit
val mk_stt_atomic_admit (u: R.universe) (t pre post: R.term) : R.term
val mk_stt_atomic_admit (u: R.universe) (t pre post: R.term) : R.term
let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 147, "start_col": 0, "start_line": 142 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u76: FStar.Stubs.Reflection.Types.universe -> t: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.stt_atomic_admit_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_stt_atomic_admit (u: R.universe) (t pre post: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_fst
val mk_fst (u1 u2: R.universe) (a1 a2 e: R.term) : R.term
val mk_fst (u1 u2: R.universe) (a1 a2 e: R.term) : R.term
let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 78, "start_col": 0, "start_line": 73 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u1: FStar.Stubs.Reflection.Types.universe -> u2: FStar.Stubs.Reflection.Types.universe -> a1: FStar.Stubs.Reflection.Types.term -> a2: FStar.Stubs.Reflection.Types.term -> e: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.fst_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_fst (u1 u2: R.universe) (a1 a2 e: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.pure_lid
val pure_lid : Prims.list Prims.string
let pure_lid = mk_pulse_lib_core_lid "pure"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 102, "start_col": 0, "start_line": 102 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let pure_lid =
mk_pulse_lib_core_lid "pure"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.pulse_lib_forall
val pulse_lib_forall : Prims.list Prims.string
let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 104, "start_col": 0, "start_line": 104 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let pulse_lib_forall =
["Pulse"; "Lib"; "Forall"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_atomic_admit_lid
val stt_atomic_admit_lid : Prims.list Prims.string
let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 67, "end_line": 141, "start_col": 0, "start_line": 141 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_atomic_admit_lid =
mk_pulse_lib_core_lid "stt_atomic_admit"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_unobservable_fv
val stt_unobservable_fv : FStar.Stubs.Reflection.Types.fv
let stt_unobservable_fv = R.pack_fv stt_unobservable_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 177, "start_col": 0, "start_line": 177 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.stt_unobservable_lid" ]
[]
false
false
false
true
false
let stt_unobservable_fv =
R.pack_fv stt_unobservable_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_star
val mk_star (l r: R.term) : R.term
val mk_star (l r: R.term) : R.term
let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 100, "start_col": 0, "start_line": 96 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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: FStar.Stubs.Reflection.Types.term -> r: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.star_lid" ]
[]
false
false
false
true
false
let mk_star (l r: R.term) : R.term =
let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_atomic_fv
val stt_atomic_fv : FStar.Stubs.Reflection.Types.fv
let stt_atomic_fv = R.pack_fv stt_atomic_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 174, "start_col": 0, "start_line": 174 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.stt_atomic_lid" ]
[]
false
false
false
true
false
let stt_atomic_fv =
R.pack_fv stt_atomic_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_tm
val stt_tm : FStar.Stubs.Reflection.Types.term
let stt_tm = R.pack_ln (R.Tv_FVar stt_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 166, "start_col": 0, "start_line": 166 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.stt_fv" ]
[]
false
false
false
true
false
let stt_tm =
R.pack_ln (R.Tv_FVar stt_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_atomic_lid
val stt_atomic_lid : Prims.list Prims.string
let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 173, "start_col": 0, "start_line": 173 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_atomic_lid =
mk_pulse_lib_core_lid "stt_atomic"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.pulse_lib_reference
val pulse_lib_reference : Prims.list Prims.string
let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 118, "start_col": 0, "start_line": 118 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let pulse_lib_reference =
["Pulse"; "Lib"; "Reference"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.elim_pure_lid
val elim_pure_lid : Prims.list Prims.string
let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 161, "start_col": 0, "start_line": 161 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let elim_pure_lid =
mk_pulse_lib_core_lid "elim_pure"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_snd
val mk_snd (u1 u2: R.universe) (a1 a2 e: R.term) : R.term
val mk_snd (u1 u2: R.universe) (a1 a2 e: R.term) : R.term
let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 85, "start_col": 0, "start_line": 80 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u1: FStar.Stubs.Reflection.Types.universe -> u2: FStar.Stubs.Reflection.Types.universe -> a1: FStar.Stubs.Reflection.Types.term -> a2: FStar.Stubs.Reflection.Types.term -> e: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.snd_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_snd (u1 u2: R.universe) (a1 a2 e: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.fst_lid
val fst_lid : Prims.list Prims.string
let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 54, "end_line": 64, "start_col": 0, "start_line": 64 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let fst_lid =
["FStar"; "Pervasives"; "Native"; "fst"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.exists_lid
val exists_lid : Prims.list Prims.string
let exists_lid = mk_pulse_lib_core_lid "op_exists_Star"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 103, "start_col": 0, "start_line": 103 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let exists_lid =
mk_pulse_lib_core_lid "op_exists_Star"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.snd_lid
val snd_lid : Prims.list Prims.string
let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 54, "end_line": 65, "start_col": 0, "start_line": 65 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let snd_lid =
["FStar"; "Pervasives"; "Native"; "snd"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_stt_comp
val mk_stt_comp (u: R.universe) (res pre post: R.term) : Tot R.term
val mk_stt_comp (u: R.universe) (res pre post: R.term) : Tot R.term
let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 171, "start_col": 0, "start_line": 167 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u92: FStar.Stubs.Reflection.Types.universe -> res: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "Pulse.Reflection.Util.stt_fv", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_stt_comp (u: R.universe) (res pre post: R.term) : Tot R.term =
let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_eq2
val mk_eq2 (u: R.universe) (ty e1 e2: R.term) : R.term
val mk_eq2 (u: R.universe) (ty e1 e2: R.term) : R.term
let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 131, "start_col": 0, "start_line": 126 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u60: FStar.Stubs.Reflection.Types.universe -> ty: FStar.Stubs.Reflection.Types.term -> e1: FStar.Stubs.Reflection.Types.term -> e2: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Reflection.Const.eq2_qn", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_eq2 (u: R.universe) (ty e1 e2: R.term) : R.term =
let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.inv_lid
val inv_lid : Prims.list Prims.string
let inv_lid = mk_pulse_lib_core_lid "inv"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 90, "start_col": 0, "start_line": 90 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let inv_lid =
mk_pulse_lib_core_lid "inv"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_pure
val mk_pure (p: R.term) : R.term
val mk_pure (p: R.term) : R.term
let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 114, "start_col": 0, "start_line": 111 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.pure_lid" ]
[]
false
false
false
true
false
let mk_pure (p: R.term) : R.term =
let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.add_inv_lid
val add_inv_lid : Prims.list Prims.string
let add_inv_lid = mk_pulse_lib_core_lid "add_inv"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 159, "start_col": 0, "start_line": 159 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let add_inv_lid =
mk_pulse_lib_core_lid "add_inv"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.args_of
val args_of : tms: Prims.list FStar.Stubs.Reflection.Types.term -> Prims.list (FStar.Stubs.Reflection.Types.term * FStar.Stubs.Reflection.V2.Data.aqualv)
let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 109, "start_col": 0, "start_line": 108 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
tms: Prims.list FStar.Stubs.Reflection.Types.term -> Prims.list (FStar.Stubs.Reflection.Types.term * FStar.Stubs.Reflection.V2.Data.aqualv)
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "FStar.Stubs.Reflection.Types.term", "FStar.List.Tot.Base.map", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.Q_Explicit" ]
[]
false
false
false
true
false
let args_of (tms: list R.term) =
List.Tot.map (fun x -> x, R.Q_Explicit) tms
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.emp_inames_lid
val emp_inames_lid : Prims.list Prims.string
let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 157, "start_col": 0, "start_line": 157 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let emp_inames_lid =
mk_pulse_lib_core_lid "emp_inames"
false
Hacl.Impl.Load56.fst
Hacl.Impl.Load56.load_32_bytes
val load_32_bytes: out:lbuffer uint64 5ul -> b:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h out /\ live h b) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F56.as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\ F56.qelem_fits h1 out (1, 1, 1, 1, 1) )
val load_32_bytes: out:lbuffer uint64 5ul -> b:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h out /\ live h b) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F56.as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\ F56.qelem_fits h1 out (1, 1, 1, 1, 1) )
let load_32_bytes out b = let h0 = ST.get() in let b0 = hload56_le' b 0ul in let b1 = hload56_le' b 7ul in let b2 = hload56_le' b 14ul in let b3 = hload56_le' b 21ul in let b4 = uint_from_bytes_le #U32 (sub b 28ul 4ul) in let b4 = to_u64 b4 in lemma_reveal_uint_to_bytes_le #U32 (as_seq h0 (gsub b 28ul 4ul)); lemma_load_32_bytes (as_seq h0 b) b0 b1 b2 b3 b4; Hacl.Bignum25519.make_u64_5 out b0 b1 b2 b3 b4
{ "file_name": "code/ed25519/Hacl.Impl.Load56.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 235, "start_col": 0, "start_line": 225 }
module Hacl.Impl.Load56 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.ByteSequence open Lib.Buffer open Lib.ByteBuffer module F56 = Hacl.Impl.BignumQ.Mul module S56 = Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val hload56_le: b:lbuffer uint8 64ul -> off:size_t{v off <= 56} -> Stack uint64 (requires fun h -> live h b) (ensures fun h0 z h1 -> h0 == h1 /\ v z < 0x100000000000000 /\ v z == nat_from_bytes_le (Seq.slice (as_seq h0 b) (v off) (v off + 7)) ) let hload56_le b off = let h0 = ST.get() in let b8 = sub b off 8ul in let z = uint_from_bytes_le b8 in let z' = z &. u64 0xffffffffffffff in assert_norm (0xffffffffffffff == pow2 56 - 1); assert_norm (0x100000000000000 == pow2 56 ); calc (==) { v z' <: nat; (==) { } v (z &. u64 0xffffffffffffff); (==) { logand_spec z (u64 0xffffffffffffff) } v z `logand_v` 0xffffffffffffff; (==) { assert_norm(pow2 56 - 1 == 0xffffffffffffff); UInt.logand_mask (UInt.to_uint_t 64 (v z)) 56 } (v z % pow2 56); (==) { lemma_reveal_uint_to_bytes_le #U64 #SEC (as_seq h0 b8) } nat_from_bytes_le (as_seq h0 b8) % pow2 56; (==) { nat_from_intseq_le_slice_lemma (as_seq h0 b8) 7 } (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) + pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) % pow2 56; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7)) (pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56); FStar.Math.Lemmas.swap_mul (pow2 (7 * 8)) (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)); FStar.Math.Lemmas.cancel_mul_mod (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56) } nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) <: nat; }; assert (Seq.equal (Seq.slice (as_seq h0 b) (v off) (v off + 7)) (Seq.slice (as_seq h0 b8) 0 7)); z' let lemma_nat_from_bytes_le_append (k1 k2:bytes) : Lemma (requires Seq.length k1 + Seq.length k2 <= max_size_t) (ensures nat_from_bytes_le (Seq.append k1 k2) == nat_from_bytes_le k1 + pow2 (Seq.length k1 * 8) * nat_from_bytes_le k2) = let k = Seq.append k1 k2 in let n = Seq.length k1 + Seq.length k2 in nat_from_intseq_le_slice_lemma #U8 #SEC #n k (Seq.length k1); assert (k1 `Seq.equal` Seq.slice k 0 (Seq.length k1)); assert (k2 `Seq.equal` Seq.slice k (Seq.length k1) n) #push-options "--z3rlimit 100" let lemma_load_64_bytes (k:lbytes 64) (b0 b1 b2 b3 b4 b5 b6 b7 b8 b9:uint64) : Lemma (requires v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\ v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\ v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\ v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\ v b4 == nat_from_bytes_le (Seq.slice k 28 35) /\ v b5 == nat_from_bytes_le (Seq.slice k 35 42) /\ v b6 == nat_from_bytes_le (Seq.slice k 42 49) /\ v b7 == nat_from_bytes_le (Seq.slice k 49 56) /\ v b8 == nat_from_bytes_le (Seq.slice k 56 63) /\ v b9 == v (Seq.index k 63) ) (ensures S56.wide_as_nat5 (b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) == nat_from_bytes_le k) = lemma_nat_from_bytes_le_append (Seq.slice k 0 7) (Seq.slice k 7 14); lemma_nat_from_bytes_le_append (Seq.slice k 0 14) (Seq.slice k 14 21); lemma_nat_from_bytes_le_append (Seq.slice k 0 21) (Seq.slice k 21 28); lemma_nat_from_bytes_le_append (Seq.slice k 0 28) (Seq.slice k 28 35); lemma_nat_from_bytes_le_append (Seq.slice k 0 35) (Seq.slice k 35 42); lemma_nat_from_bytes_le_append (Seq.slice k 0 42) (Seq.slice k 42 49); lemma_nat_from_bytes_le_append (Seq.slice k 0 49) (Seq.slice k 49 56); lemma_nat_from_bytes_le_append (Seq.slice k 0 56) (Seq.slice k 56 63); lemma_nat_from_bytes_le_append (Seq.slice k 0 63) (Seq.create 1 (Seq.index k 63)); assert (Seq.append (Seq.slice k 0 7) (Seq.slice k 7 14) `Seq.equal` Seq.slice k 0 14); assert (Seq.append (Seq.slice k 0 14) (Seq.slice k 14 21) `Seq.equal` Seq.slice k 0 21); assert (Seq.append (Seq.slice k 0 21) (Seq.slice k 21 28) `Seq.equal` Seq.slice k 0 28); assert (Seq.append (Seq.slice k 0 28) (Seq.slice k 28 35) `Seq.equal` Seq.slice k 0 35); assert (Seq.append (Seq.slice k 0 35) (Seq.slice k 35 42) `Seq.equal` Seq.slice k 0 42); assert (Seq.append (Seq.slice k 0 42) (Seq.slice k 42 49) `Seq.equal` Seq.slice k 0 49); assert (Seq.append (Seq.slice k 0 49) (Seq.slice k 49 56) `Seq.equal` Seq.slice k 0 56); assert (Seq.append (Seq.slice k 0 56) (Seq.slice k 56 63) `Seq.equal` Seq.slice k 0 63); assert (Seq.append (Seq.slice k 0 63) (Seq.create 1 (Seq.index k 63)) `Seq.equal` k); nat_from_intseq_le_lemma0 (Seq.create 1 (Seq.index k 63)); assert_norm (pow2 56 == 0x100000000000000); assert_norm (pow2 112 == 0x10000000000000000000000000000); assert_norm (pow2 168 == 0x1000000000000000000000000000000000000000000); assert_norm (pow2 224 == 0x100000000000000000000000000000000000000000000000000000000); assert_norm (pow2 280 == 0x10000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 336 == 0x1000000000000000000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 392 == 0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 448 == 0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 504 == 0x1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) #pop-options val load_64_bytes: out:lbuffer uint64 10ul -> b:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h out /\ live h b) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F56.wide_as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\ F56.qelem_wide_fits h1 out (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) ) [@CInline] let load_64_bytes out b = let h0 = ST.get() in let b0 = hload56_le b 0ul in let b1 = hload56_le b 7ul in let b2 = hload56_le b 14ul in let b3 = hload56_le b 21ul in let b4 = hload56_le b 28ul in let b5 = hload56_le b 35ul in let b6 = hload56_le b 42ul in let b7 = hload56_le b 49ul in let b8 = hload56_le b 56ul in let b63 = b.(63ul) in let b9 = to_u64 b63 in lemma_load_64_bytes (as_seq h0 b) b0 b1 b2 b3 b4 b5 b6 b7 b8 b9; Hacl.Bignum25519.make_u64_10 out b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 inline_for_extraction noextract val hload56_le': b:lbuffer uint8 32ul -> off:size_t{v off <= 21} -> Stack uint64 (requires fun h -> live h b) (ensures fun h0 z h1 -> h0 == h1 /\ v z < 0x100000000000000 /\ v z == nat_from_bytes_le (Seq.slice (as_seq h0 b) (v off) (v off + 7)) ) let hload56_le' b off = let h0 = ST.get() in let b8 = sub b off 8ul in let z = uint_from_bytes_le b8 in let z' = z &. u64 0xffffffffffffff in assert_norm (0xffffffffffffff == pow2 56 - 1); assert_norm (0x100000000000000 == pow2 56 ); calc (==) { v z' <: nat; (==) { } v (z &. u64 0xffffffffffffff); (==) { logand_spec z (u64 0xffffffffffffff) } v z `logand_v` 0xffffffffffffff; (==) { assert_norm(pow2 56 - 1 == 0xffffffffffffff); UInt.logand_mask (UInt.to_uint_t 64 (v z)) 56 } (v z % pow2 56); (==) { lemma_reveal_uint_to_bytes_le #U64 #SEC (as_seq h0 b8) } nat_from_bytes_le (as_seq h0 b8) % pow2 56; (==) { nat_from_intseq_le_slice_lemma (as_seq h0 b8) 7 } (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) + pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) % pow2 56; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7)) (pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56); FStar.Math.Lemmas.swap_mul (pow2 (7 * 8)) (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)); FStar.Math.Lemmas.cancel_mul_mod (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56) } nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) <: nat; }; assert (Seq.equal (Seq.slice (as_seq h0 b) (v off) (v off + 7)) (Seq.slice (as_seq h0 b8) 0 7)); z' let lemma_load_32_bytes (k:lbytes 32) (b0 b1 b2 b3 b4:uint64) : Lemma (requires v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\ v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\ v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\ v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\ v b4 == nat_from_bytes_le (Seq.slice k 28 32)) (ensures S56.as_nat5 (b0, b1, b2, b3, b4) == nat_from_bytes_le k) = lemma_nat_from_bytes_le_append (Seq.slice k 0 7) (Seq.slice k 7 14); lemma_nat_from_bytes_le_append (Seq.slice k 0 14) (Seq.slice k 14 21); lemma_nat_from_bytes_le_append (Seq.slice k 0 21) (Seq.slice k 21 28); lemma_nat_from_bytes_le_append (Seq.slice k 0 28) (Seq.slice k 28 32); assert (Seq.append (Seq.slice k 0 7) (Seq.slice k 7 14) `Seq.equal` Seq.slice k 0 14); assert (Seq.append (Seq.slice k 0 14) (Seq.slice k 14 21) `Seq.equal` Seq.slice k 0 21); assert (Seq.append (Seq.slice k 0 21) (Seq.slice k 21 28) `Seq.equal` Seq.slice k 0 28); assert (Seq.append (Seq.slice k 0 28) (Seq.slice k 28 32) `Seq.equal` k); assert_norm (pow2 56 == 0x100000000000000); assert_norm (pow2 112 == 0x10000000000000000000000000000); assert_norm (pow2 168 == 0x1000000000000000000000000000000000000000000); assert_norm (pow2 224 == 0x100000000000000000000000000000000000000000000000000000000) val load_32_bytes: out:lbuffer uint64 5ul -> b:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h out /\ live h b) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F56.as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\ F56.qelem_fits h1 out (1, 1, 1, 1, 1) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "Hacl.Impl.BignumQ.Mul.fsti.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Load56.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": "S56" }, { "abbrev": true, "full_module": "Hacl.Impl.BignumQ.Mul", "short_module": "F56" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.uint8", "Hacl.Bignum25519.make_u64_5", "Prims.unit", "Hacl.Impl.Load56.lemma_load_32_bytes", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.ByteSequence.lemma_reveal_uint_to_bytes_le", "Lib.IntTypes.U32", "Lib.IntTypes.SEC", "Lib.Buffer.gsub", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.to_u64", "Lib.ByteBuffer.uint_from_bytes_le", "Lib.IntTypes.uint_t", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.U8", "Lib.IntTypes.mk_int", "Lib.IntTypes.PUB", "Lib.Buffer.sub", "Hacl.Impl.Load56.hload56_le'", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let load_32_bytes out b =
let h0 = ST.get () in let b0 = hload56_le' b 0ul in let b1 = hload56_le' b 7ul in let b2 = hload56_le' b 14ul in let b3 = hload56_le' b 21ul in let b4 = uint_from_bytes_le #U32 (sub b 28ul 4ul) in let b4 = to_u64 b4 in lemma_reveal_uint_to_bytes_le #U32 (as_seq h0 (gsub b 28ul 4ul)); lemma_load_32_bytes (as_seq h0 b) b0 b1 b2 b3 b4; Hacl.Bignum25519.make_u64_5 out b0 b1 b2 b3 b4
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_lid
val stt_lid : Prims.list Prims.string
let stt_lid = mk_pulse_lib_core_lid "stt"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 164, "start_col": 0, "start_line": 164 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_lid =
mk_pulse_lib_core_lid "stt"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.forall_lid
val forall_lid : Prims.list Prims.string
let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 57, "end_line": 107, "start_col": 0, "start_line": 107 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s]
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_forall_lid" ]
[]
false
false
false
true
false
let forall_lid =
mk_pulse_lib_forall_lid "op_forall_Star"
false
MerkleTree.Low.fst
MerkleTree.Low.create_empty_mt
val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ()))
val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\ merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ()))
let create_empty_mt hsz hash_spec hash_fun r = [@inline_let] let hrg = hreg hsz in [@inline_let] let hvrg = hvreg hsz in [@inline_let] let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt
{ "file_name": "src/MerkleTree.Low.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 4, "end_line": 376, "start_col": 0, "start_line": 348 }
module MerkleTree.Low open EverCrypt.Helpers open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTH = MerkleTree.New.High module MTS = MerkleTree.Spec open Lib.IntTypes open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions open MerkleTree.Low.VectorExtras #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE} /// Low-level Merkle tree data structure /// // NOTE: because of a lack of 64-bit LowStar.Buffer support, currently // we cannot change below to some other types. type index_t = uint32_t let uint32_32_max = 4294967295ul inline_for_extraction let uint32_max = 4294967295UL let uint64_max = 18446744073709551615UL let offset_range_limit = uint32_max type offset_t = uint64_t inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64 inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32 private inline_for_extraction let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit private inline_for_extraction let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t = [@inline_let] let diff = U64.sub_mod index tree in assert (diff <= offset_range_limit); Int.Cast.uint64_to_uint32 diff private inline_for_extraction let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i) private inline_for_extraction let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) = U64.add tree (u32_64 i) inline_for_extraction val merkle_tree_size_lg: uint32_t let merkle_tree_size_lg = 32ul // A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate // a Merkle path for each element from the index `i` to `j-1`. // - Parameters // `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values. // `rhs_ok`: to check the rightmost hashes are up-to-date // `rhs`: a store for "rightmost" hashes, manipulated only when required to // calculate some merkle paths that need the rightmost hashes // as a part of them. // `mroot`: during the construction of `rhs` we can also calculate the Merkle // root of the tree. If `rhs_ok` is true then it has the up-to-date // root value. noeq type merkle_tree = | MT: hash_size:hash_size_t -> offset:offset_t -> i:index_t -> j:index_t{i <= j /\ add64_fits offset j} -> hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} -> rhs_ok:bool -> rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} -> mroot:hash #hash_size -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> merkle_tree type mt_p = B.pointer merkle_tree type const_mt_p = const_pointer merkle_tree inline_for_extraction let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool = j >= i && add64_fits offset j && V.size_of hs = merkle_tree_size_lg && V.size_of rhs = merkle_tree_size_lg // The maximum number of currently held elements in the tree is (2^32 - 1). // cwinter: even when using 64-bit indices, we fail if the underlying 32-bit // vector is full; this can be fixed if necessary. private inline_for_extraction val mt_not_full_nst: mtv:merkle_tree -> Tot bool let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max val mt_not_full: HS.mem -> mt_p -> GTot bool let mt_not_full h mt = mt_not_full_nst (B.get h mt 0) /// (Memory) Safety val offset_of: i:index_t -> Tot index_t let offset_of i = if i % 2ul = 0ul then i else i - 1ul // `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1` // at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid // element. inline_for_extraction noextract val mt_safe_elts: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> GTot Type0 (decreases (32 - U32.v lv)) let rec mt_safe_elts #hsz h lv hs i j = if lv = merkle_tree_size_lg then true else (let ofs = offset_of i in V.size_of (V.get h hs lv) == j - ofs /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)) #push-options "--initial_fuel 1 --max_fuel 1" val mt_safe_elts_constr: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\ mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) (ensures (mt_safe_elts #hsz h lv hs i j)) let mt_safe_elts_constr #_ h lv hs i j = () val mt_safe_elts_head: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (V.size_of (V.get h hs lv) == j - offset_of i)) let mt_safe_elts_head #_ h lv hs i j = () val mt_safe_elts_rec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (mt_safe_elts #hsz h lv hs i j)) (ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))) let mt_safe_elts_rec #_ h lv hs i j = () val mt_safe_elts_init: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> Lemma (requires (V.forall_ h hs lv (V.size_of hs) (fun hv -> V.size_of hv = 0ul))) (ensures (mt_safe_elts #hsz h lv hs 0ul 0ul)) (decreases (32 - U32.v lv)) let rec mt_safe_elts_init #hsz h lv hs = if lv = merkle_tree_size_lg then () else mt_safe_elts_init #hsz h (lv + 1ul) hs #pop-options val mt_safe_elts_preserved: #hsz:hash_size_t -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 hs /\ mt_safe_elts #hsz h0 lv hs i j /\ loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\ modifies p h0 h1)) (ensures (mt_safe_elts #hsz h1 lv hs i j)) (decreases (32 - U32.v lv)) [SMTPat (V.live h0 hs); SMTPat (mt_safe_elts #hsz h0 lv hs i j); SMTPat (loc_disjoint p (RV.loc_rvector hs)); SMTPat (modifies p h0 h1)] #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 = if lv = merkle_tree_size_lg then () else (V.get_preserved hs lv p h0 h1; mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1) #pop-options // `mt_safe` is the invariant of a Merkle tree through its lifetime. // It includes liveness, regionality, disjointness (to each data structure), // and valid element access (`mt_safe_elts`). inline_for_extraction noextract val mt_safe: HS.mem -> mt_p -> GTot Type0 let mt_safe h mt = B.live h mt /\ B.freeable mt /\ (let mtv = B.get h mt 0 in // Liveness & Accessibility RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\ // Regionality HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\ HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\ HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\ HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\ HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv))) // Since a Merkle tree satisfies regionality, it's ok to take all regions from // a tree pointer as a location of the tree. val mt_loc: mt_p -> GTot loc let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt) val mt_safe_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (B.get h0 mt 0 == B.get h1 mt 0 /\ mt_safe h1 mt)) let mt_safe_preserved mt p h0 h1 = assert (loc_includes (mt_loc mt) (B.loc_buffer mt)); let mtv = B.get h0 mt 0 in assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv))); assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv))); assert (loc_includes (mt_loc mt) (B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv)))); RV.rv_inv_preserved (MT?.hs mtv) p h0 h1; RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1; Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1; V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv)); mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1 /// Lifting to a high-level Merkle tree structure val mt_safe_elts_spec: #hsz:hash_size_t -> h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} -> hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} -> i:index_t -> j:index_t{j >= i} -> Lemma (requires (RV.rv_inv h hs /\ mt_safe_elts #hsz h lv hs i j)) (ensures (MTH.hs_wf_elts #(U32.v hsz) (U32.v lv) (RV.as_seq h hs) (U32.v i) (U32.v j))) (decreases (32 - U32.v lv)) #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_safe_elts_spec #_ h lv hs i j = if lv = merkle_tree_size_lg then () else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul) #pop-options val merkle_tree_lift: h:HS.mem -> mtv:merkle_tree{ RV.rv_inv h (MT?.hs mtv) /\ RV.rv_inv h (MT?.rhs mtv) /\ Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\ mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r}) let merkle_tree_lift h mtv = mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv); MTH.MT #(U32.v (MT?.hash_size mtv)) (U32.v (MT?.i mtv)) (U32.v (MT?.j mtv)) (RV.as_seq h (MT?.hs mtv)) (MT?.rhs_ok mtv) (RV.as_seq h (MT?.rhs mtv)) (Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv)) (Ghost.reveal (MT?.hash_spec mtv)) val mt_lift: h:HS.mem -> mt:mt_p{mt_safe h mt} -> GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r}) let mt_lift h mt = merkle_tree_lift h (B.get h mt 0) val mt_preserved: mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (mt_safe h0 mt /\ loc_disjoint p (mt_loc mt) /\ modifies p h0 h1)) (ensures (mt_safe_preserved mt p h0 h1; mt_lift h0 mt == mt_lift h1 mt)) let mt_preserved mt p h0 h1 = assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer mt)); B.modifies_buffer_elim mt p h0 h1; assert (B.get h0 mt 0 == B.get h1 mt 0); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.hs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (RV.loc_rvector (MT?.rhs (B.get h0 mt 0)))); assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt)) (B.loc_buffer (MT?.mroot (B.get h0 mt 0)))); RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1; RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1; B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1 /// Construction // Note that the public function for creation is `mt_create` defined below, // which builds a tree with an initial hash. #push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" private val create_empty_mt: hash_size:hash_size_t -> hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) -> hash_fun:hash_fun_t #hash_size #hash_spec -> r:HST.erid -> HST.ST mt_p (requires (fun _ -> true)) (ensures (fun h0 mt h1 -> let dmt = B.get h1 mt 0 in // memory safety B.frameOf mt = r /\ modifies (mt_loc mt) h0 h1 /\ mt_safe h1 mt /\ mt_not_full h1 mt /\ // correctness MT?.hash_size dmt = hash_size /\ MT?.offset dmt = 0UL /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "MerkleTree.Low.VectorExtras.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.Low.VectorExtras", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree", "short_module": null }, { "abbrev": 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": 1, "initial_ifuel": 1, "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": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hash_size: MerkleTree.Low.Datastructures.hash_size_t -> hash_spec: FStar.Ghost.erased MerkleTree.Spec.hash_fun_t -> hash_fun: MerkleTree.Low.Hashfunctions.hash_fun_t -> r: FStar.HyperStack.ST.erid -> FStar.HyperStack.ST.ST MerkleTree.Low.mt_p
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Ghost.erased", "MerkleTree.Spec.hash_fun_t", "FStar.UInt32.v", "MerkleTree.Low.Hashfunctions.hash_fun_t", "FStar.HyperStack.ST.erid", "Prims.unit", "MerkleTree.Low.mt_safe_elts_preserved", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Regional.__proj__Rgl__item__r_sep", "MerkleTree.Low.Datastructures.hash", "LowStar.RVector.as_seq_preserved", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.mt_p", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.mbuffer", "MerkleTree.Low.merkle_tree", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "FStar.Monotonic.HyperHeap.rid", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.freeable", "LowStar.Buffer.malloc", "MerkleTree.Low.MT", "FStar.UInt64.__uint_to_t", "LowStar.Regional.rg_alloc", "FStar.HyperStack.ST.new_region", "LowStar.Vector.loc_vector", "LowStar.Vector.loc_vector_within_included", "LowStar.Vector.size_of", "LowStar.RVector.rv_inv_preserved", "Prims._assert", "FStar.Seq.Base.seq", "LowStar.Regional.__proj__Rgl__item__repr", "LowStar.RVector.as_seq", "FStar.Seq.Base.create", "MerkleTree.New.High.hash_init", "LowStar.RVector.rvector", "LowStar.RVector.alloc_rid", "MerkleTree.Low.merkle_tree_size_lg", "MerkleTree.Low.mt_safe_elts_init", "LowStar.Regional.regional", "MerkleTree.Low.Datastructures.hash_vv", "MerkleTree.Low.Datastructures.hvvreg", "MerkleTree.Low.Datastructures.hvreg", "MerkleTree.Low.Datastructures.hreg" ]
[]
false
true
false
false
false
let create_empty_mt hsz hash_spec hash_fun r =
[@@ inline_let ]let hrg = hreg hsz in [@@ inline_let ]let hvrg = hvreg hsz in [@@ inline_let ]let hvvrg = hvvreg hsz in let hs_region = HST.new_region r in let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in let h0 = HST.get () in mt_safe_elts_init #hsz h0 0ul hs; let rhs_region = HST.new_region r in let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in let h1 = HST.get () in assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz))); RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1; RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1; V.loc_vector_within_included hs 0ul (V.size_of hs); mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1; let mroot_region = HST.new_region r in let mroot = rg_alloc hrg mroot_region in let h2 = HST.get () in RV.as_seq_preserved hs loc_none h1 h2; RV.as_seq_preserved rhs loc_none h1 h2; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2; let mt = B.malloc r (MT hsz 0uL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in let h3 = HST.get () in RV.as_seq_preserved hs loc_none h2 h3; RV.as_seq_preserved rhs loc_none h2 h3; Rgl?.r_sep hrg mroot loc_none h2 h3; mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3; mt
false
Hacl.Impl.Load56.fst
Hacl.Impl.Load56.load_64_bytes
val load_64_bytes: out:lbuffer uint64 10ul -> b:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h out /\ live h b) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F56.wide_as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\ F56.qelem_wide_fits h1 out (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) )
val load_64_bytes: out:lbuffer uint64 10ul -> b:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h out /\ live h b) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F56.wide_as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\ F56.qelem_wide_fits h1 out (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) )
let load_64_bytes out b = let h0 = ST.get() in let b0 = hload56_le b 0ul in let b1 = hload56_le b 7ul in let b2 = hload56_le b 14ul in let b3 = hload56_le b 21ul in let b4 = hload56_le b 28ul in let b5 = hload56_le b 35ul in let b6 = hload56_le b 42ul in let b7 = hload56_le b 49ul in let b8 = hload56_le b 56ul in let b63 = b.(63ul) in let b9 = to_u64 b63 in lemma_load_64_bytes (as_seq h0 b) b0 b1 b2 b3 b4 b5 b6 b7 b8 b9; Hacl.Bignum25519.make_u64_10 out b0 b1 b2 b3 b4 b5 b6 b7 b8 b9
{ "file_name": "code/ed25519/Hacl.Impl.Load56.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 145, "start_col": 0, "start_line": 131 }
module Hacl.Impl.Load56 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.ByteSequence open Lib.Buffer open Lib.ByteBuffer module F56 = Hacl.Impl.BignumQ.Mul module S56 = Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val hload56_le: b:lbuffer uint8 64ul -> off:size_t{v off <= 56} -> Stack uint64 (requires fun h -> live h b) (ensures fun h0 z h1 -> h0 == h1 /\ v z < 0x100000000000000 /\ v z == nat_from_bytes_le (Seq.slice (as_seq h0 b) (v off) (v off + 7)) ) let hload56_le b off = let h0 = ST.get() in let b8 = sub b off 8ul in let z = uint_from_bytes_le b8 in let z' = z &. u64 0xffffffffffffff in assert_norm (0xffffffffffffff == pow2 56 - 1); assert_norm (0x100000000000000 == pow2 56 ); calc (==) { v z' <: nat; (==) { } v (z &. u64 0xffffffffffffff); (==) { logand_spec z (u64 0xffffffffffffff) } v z `logand_v` 0xffffffffffffff; (==) { assert_norm(pow2 56 - 1 == 0xffffffffffffff); UInt.logand_mask (UInt.to_uint_t 64 (v z)) 56 } (v z % pow2 56); (==) { lemma_reveal_uint_to_bytes_le #U64 #SEC (as_seq h0 b8) } nat_from_bytes_le (as_seq h0 b8) % pow2 56; (==) { nat_from_intseq_le_slice_lemma (as_seq h0 b8) 7 } (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) + pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) % pow2 56; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7)) (pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56); FStar.Math.Lemmas.swap_mul (pow2 (7 * 8)) (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)); FStar.Math.Lemmas.cancel_mul_mod (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56) } nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) <: nat; }; assert (Seq.equal (Seq.slice (as_seq h0 b) (v off) (v off + 7)) (Seq.slice (as_seq h0 b8) 0 7)); z' let lemma_nat_from_bytes_le_append (k1 k2:bytes) : Lemma (requires Seq.length k1 + Seq.length k2 <= max_size_t) (ensures nat_from_bytes_le (Seq.append k1 k2) == nat_from_bytes_le k1 + pow2 (Seq.length k1 * 8) * nat_from_bytes_le k2) = let k = Seq.append k1 k2 in let n = Seq.length k1 + Seq.length k2 in nat_from_intseq_le_slice_lemma #U8 #SEC #n k (Seq.length k1); assert (k1 `Seq.equal` Seq.slice k 0 (Seq.length k1)); assert (k2 `Seq.equal` Seq.slice k (Seq.length k1) n) #push-options "--z3rlimit 100" let lemma_load_64_bytes (k:lbytes 64) (b0 b1 b2 b3 b4 b5 b6 b7 b8 b9:uint64) : Lemma (requires v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\ v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\ v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\ v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\ v b4 == nat_from_bytes_le (Seq.slice k 28 35) /\ v b5 == nat_from_bytes_le (Seq.slice k 35 42) /\ v b6 == nat_from_bytes_le (Seq.slice k 42 49) /\ v b7 == nat_from_bytes_le (Seq.slice k 49 56) /\ v b8 == nat_from_bytes_le (Seq.slice k 56 63) /\ v b9 == v (Seq.index k 63) ) (ensures S56.wide_as_nat5 (b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) == nat_from_bytes_le k) = lemma_nat_from_bytes_le_append (Seq.slice k 0 7) (Seq.slice k 7 14); lemma_nat_from_bytes_le_append (Seq.slice k 0 14) (Seq.slice k 14 21); lemma_nat_from_bytes_le_append (Seq.slice k 0 21) (Seq.slice k 21 28); lemma_nat_from_bytes_le_append (Seq.slice k 0 28) (Seq.slice k 28 35); lemma_nat_from_bytes_le_append (Seq.slice k 0 35) (Seq.slice k 35 42); lemma_nat_from_bytes_le_append (Seq.slice k 0 42) (Seq.slice k 42 49); lemma_nat_from_bytes_le_append (Seq.slice k 0 49) (Seq.slice k 49 56); lemma_nat_from_bytes_le_append (Seq.slice k 0 56) (Seq.slice k 56 63); lemma_nat_from_bytes_le_append (Seq.slice k 0 63) (Seq.create 1 (Seq.index k 63)); assert (Seq.append (Seq.slice k 0 7) (Seq.slice k 7 14) `Seq.equal` Seq.slice k 0 14); assert (Seq.append (Seq.slice k 0 14) (Seq.slice k 14 21) `Seq.equal` Seq.slice k 0 21); assert (Seq.append (Seq.slice k 0 21) (Seq.slice k 21 28) `Seq.equal` Seq.slice k 0 28); assert (Seq.append (Seq.slice k 0 28) (Seq.slice k 28 35) `Seq.equal` Seq.slice k 0 35); assert (Seq.append (Seq.slice k 0 35) (Seq.slice k 35 42) `Seq.equal` Seq.slice k 0 42); assert (Seq.append (Seq.slice k 0 42) (Seq.slice k 42 49) `Seq.equal` Seq.slice k 0 49); assert (Seq.append (Seq.slice k 0 49) (Seq.slice k 49 56) `Seq.equal` Seq.slice k 0 56); assert (Seq.append (Seq.slice k 0 56) (Seq.slice k 56 63) `Seq.equal` Seq.slice k 0 63); assert (Seq.append (Seq.slice k 0 63) (Seq.create 1 (Seq.index k 63)) `Seq.equal` k); nat_from_intseq_le_lemma0 (Seq.create 1 (Seq.index k 63)); assert_norm (pow2 56 == 0x100000000000000); assert_norm (pow2 112 == 0x10000000000000000000000000000); assert_norm (pow2 168 == 0x1000000000000000000000000000000000000000000); assert_norm (pow2 224 == 0x100000000000000000000000000000000000000000000000000000000); assert_norm (pow2 280 == 0x10000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 336 == 0x1000000000000000000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 392 == 0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 448 == 0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); assert_norm (pow2 504 == 0x1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) #pop-options val load_64_bytes: out:lbuffer uint64 10ul -> b:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h out /\ live h b) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F56.wide_as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\ F56.qelem_wide_fits h1 out (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "Hacl.Impl.BignumQ.Mul.fsti.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Load56.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": "S56" }, { "abbrev": true, "full_module": "Hacl.Impl.BignumQ.Mul", "short_module": "F56" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Lib.Buffer.lbuffer Lib.IntTypes.uint64 10ul -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.uint8", "Hacl.Bignum25519.make_u64_10", "Prims.unit", "Hacl.Impl.Load56.lemma_load_64_bytes", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.to_u64", "Lib.IntTypes.U8", "Lib.Buffer.op_Array_Access", "Hacl.Impl.Load56.hload56_le", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let load_64_bytes out b =
let h0 = ST.get () in let b0 = hload56_le b 0ul in let b1 = hload56_le b 7ul in let b2 = hload56_le b 14ul in let b3 = hload56_le b 21ul in let b4 = hload56_le b 28ul in let b5 = hload56_le b 35ul in let b6 = hload56_le b 42ul in let b7 = hload56_le b 49ul in let b8 = hload56_le b 56ul in let b63 = b.(63ul) in let b9 = to_u64 b63 in lemma_load_64_bytes (as_seq h0 b) b0 b1 b2 b3 b4 b5 b6 b7 b8 b9; Hacl.Bignum25519.make_u64_10 out b0 b1 b2 b3 b4 b5 b6 b7 b8 b9
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_stt_atomic_comp
val mk_stt_atomic_comp : obs: FStar.Stubs.Reflection.Types.term -> u105: FStar.Stubs.Reflection.Types.universe -> a: FStar.Stubs.Reflection.Types.term -> inames: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 186, "start_col": 0, "start_line": 179 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
obs: FStar.Stubs.Reflection.Types.term -> u105: FStar.Stubs.Reflection.Types.universe -> a: FStar.Stubs.Reflection.Types.term -> inames: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "Prims.Cons", "Prims.Nil", "FStar.Stubs.Reflection.Types.fv", "Pulse.Reflection.Util.stt_atomic_fv" ]
[]
false
false
false
true
false
let mk_stt_atomic_comp (obs: R.term) (u: R.universe) (a inames pre post: R.term) =
let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_stt_ghost_comp
val mk_stt_ghost_comp : u112: FStar.Stubs.Reflection.Types.universe -> a: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 196, "start_col": 0, "start_line": 192 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u112: FStar.Stubs.Reflection.Types.universe -> a: FStar.Stubs.Reflection.Types.term -> pre: FStar.Stubs.Reflection.Types.term -> post: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "Pulse.Reflection.Util.stt_ghost_fv", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_stt_ghost_comp (u: R.universe) (a pre post: R.term) =
let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_ghost_fv
val stt_ghost_fv : FStar.Stubs.Reflection.Types.fv
let stt_ghost_fv = R.pack_fv stt_ghost_lid
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 190, "start_col": 0, "start_line": 190 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.stt_ghost_lid" ]
[]
false
false
false
true
false
let stt_ghost_fv =
R.pack_fv stt_ghost_lid
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.intro_exists_erased_lid
val intro_exists_erased_lid : Prims.list Prims.string
let intro_exists_erased_lid = mk_pulse_lib_core_lid "intro_exists_erased"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 73, "end_line": 246, "start_col": 0, "start_line": 246 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t) let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit)) let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit)) let elim_exists_lid = mk_pulse_lib_core_lid "elim_exists"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let intro_exists_erased_lid =
mk_pulse_lib_core_lid "intro_exists_erased"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_ghost_lid
val stt_ghost_lid : Prims.list Prims.string
let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 189, "start_col": 0, "start_line": 189 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_ghost_lid =
mk_pulse_lib_core_lid "stt_ghost"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_ghost_arrow_with_name
val mk_ghost_arrow_with_name (s: RT.pp_name_t) (f: arrow_dom) (out: R.term) : R.term
val mk_ghost_arrow_with_name (s: RT.pp_name_t) (f: arrow_dom) (out: R.term) : R.term
let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out)))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 78, "end_line": 227, "start_col": 0, "start_line": 225 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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: FStar.Reflection.Typing.pp_name_t -> f: Pulse.Reflection.Util.arrow_dom -> out: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Reflection.Typing.pp_name_t", "Pulse.Reflection.Util.arrow_dom", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_Arrow", "Pulse.Reflection.Util.binder_of_t_q_s", "FStar.Stubs.Reflection.V2.Builtins.pack_comp", "Pulse.Reflection.Util.mk_ghost" ]
[]
false
false
false
true
false
let mk_ghost_arrow_with_name (s: RT.pp_name_t) (f: arrow_dom) (out: R.term) : R.term =
let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out)))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_ghost_tm
val stt_ghost_tm : FStar.Stubs.Reflection.Types.term
let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 191, "start_col": 0, "start_line": 191 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "Pulse.Reflection.Util.stt_ghost_fv" ]
[]
false
false
false
true
false
let stt_ghost_tm =
R.pack_ln (R.Tv_FVar stt_ghost_fv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.binder_of_t_q_s
val binder_of_t_q_s : t: FStar.Stubs.Reflection.Types.term -> q: FStar.Stubs.Reflection.V2.Data.aqualv -> s: FStar.Reflection.Typing.pp_name_t -> FStar.Stubs.Reflection.Types.binder
let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 81, "end_line": 214, "start_col": 0, "start_line": 214 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> q: FStar.Stubs.Reflection.V2.Data.aqualv -> s: FStar.Reflection.Typing.pp_name_t -> FStar.Stubs.Reflection.Types.binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Reflection.Typing.pp_name_t", "FStar.Reflection.Typing.mk_binder", "FStar.Stubs.Reflection.Types.binder" ]
[]
false
false
false
true
false
let binder_of_t_q_s (t: R.term) (q: R.aqualv) (s: RT.pp_name_t) =
RT.mk_binder s t q
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.arrow_dom
val arrow_dom : Type0
let arrow_dom = (R.term & R.aqualv)
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 218, "start_col": 0, "start_line": 218 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i)))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv" ]
[]
false
false
false
true
true
let arrow_dom =
(R.term & R.aqualv)
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.emp_inames_tm
val emp_inames_tm:R.term
val emp_inames_tm:R.term
let emp_inames_tm : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv emp_inames_lid))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 77, "end_line": 293, "start_col": 0, "start_line": 293 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t) let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit)) let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit)) let elim_exists_lid = mk_pulse_lib_core_lid "elim_exists" let intro_exists_lid = mk_pulse_lib_core_lid "intro_exists" let intro_exists_erased_lid = mk_pulse_lib_core_lid "intro_exists_erased" let mk_exists (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_forall (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv forall_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_elim_exists (u:R.universe) (a p:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv elim_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_intro_exists (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let mk_intro_exists_erased (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_erased_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let while_lid = ["Pulse"; "Lib"; "WhileLoop"; "while_loop"] let mk_while (inv cond body:R.term) : R.term = let t = R.pack_ln (R.Tv_FVar (R.pack_fv while_lid)) in let t = R.pack_ln (R.Tv_App t (inv, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (cond, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (body, R.Q_Explicit)) let vprop_eq_tm t1 t2 = let open R in let u2 = pack_universe (Uv_Succ (pack_universe (Uv_Succ (pack_universe Uv_Zero)))) in let t = pack_ln (Tv_UInst (pack_fv eq2_qn) [u2]) in let t = pack_ln (Tv_App t (pack_ln (Tv_FVar (pack_fv vprop_lid)), Q_Implicit)) in let t = pack_ln (Tv_App t (t1, Q_Explicit)) in let t = pack_ln (Tv_App t (t2, Q_Explicit)) in t
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.emp_inames_lid" ]
[]
false
false
false
true
false
let emp_inames_tm:R.term =
R.pack_ln (R.Tv_FVar (R.pack_fv emp_inames_lid))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.binder_of_t_q
val binder_of_t_q : t: FStar.Stubs.Reflection.Types.term -> q: FStar.Stubs.Reflection.V2.Data.aqualv -> FStar.Stubs.Reflection.Types.binder
let binder_of_t_q t q = RT.binder_of_t_q t q
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 213, "start_col": 0, "start_line": 213 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> q: FStar.Stubs.Reflection.V2.Data.aqualv -> FStar.Stubs.Reflection.Types.binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Reflection.Typing.binder_of_t_q", "FStar.Stubs.Reflection.Types.binder" ]
[]
false
false
false
true
false
let binder_of_t_q t q =
RT.binder_of_t_q t q
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_arrow
val mk_arrow (f: arrow_dom) (out: R.term) : R.term
val mk_arrow (f: arrow_dom) (out: R.term) : R.term
let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out)))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 74, "end_line": 221, "start_col": 0, "start_line": 219 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i)))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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: Pulse.Reflection.Util.arrow_dom -> out: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.arrow_dom", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_Arrow", "Pulse.Reflection.Util.binder_of_t_q", "FStar.Stubs.Reflection.V2.Builtins.pack_comp", "Pulse.Reflection.Util.mk_total" ]
[]
false
false
false
true
false
let mk_arrow (f: arrow_dom) (out: R.term) : R.term =
let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out)))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.vprop_eq_tm
val vprop_eq_tm : t1: FStar.Stubs.Reflection.Types.term -> t2: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
let vprop_eq_tm t1 t2 = let open R in let u2 = pack_universe (Uv_Succ (pack_universe (Uv_Succ (pack_universe Uv_Zero)))) in let t = pack_ln (Tv_UInst (pack_fv eq2_qn) [u2]) in let t = pack_ln (Tv_App t (pack_ln (Tv_FVar (pack_fv vprop_lid)), Q_Implicit)) in let t = pack_ln (Tv_App t (t1, Q_Explicit)) in let t = pack_ln (Tv_App t (t2, Q_Explicit)) in t
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 291, "start_col": 0, "start_line": 283 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t) let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit)) let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit)) let elim_exists_lid = mk_pulse_lib_core_lid "elim_exists" let intro_exists_lid = mk_pulse_lib_core_lid "intro_exists" let intro_exists_erased_lid = mk_pulse_lib_core_lid "intro_exists_erased" let mk_exists (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_forall (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv forall_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_elim_exists (u:R.universe) (a p:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv elim_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_intro_exists (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let mk_intro_exists_erased (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_erased_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let while_lid = ["Pulse"; "Lib"; "WhileLoop"; "while_loop"] let mk_while (inv cond body:R.term) : R.term = let t = R.pack_ln (R.Tv_FVar (R.pack_fv while_lid)) in let t = R.pack_ln (R.Tv_App t (inv, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (cond, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (body, R.Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
t1: FStar.Stubs.Reflection.Types.term -> t2: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.vprop_lid", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Reflection.Const.eq2_qn", "Prims.Cons", "FStar.Stubs.Reflection.Types.universe", "Prims.Nil", "FStar.Stubs.Reflection.V2.Builtins.pack_universe", "FStar.Stubs.Reflection.V2.Data.Uv_Succ", "FStar.Stubs.Reflection.V2.Data.Uv_Zero" ]
[]
false
false
false
true
false
let vprop_eq_tm t1 t2 =
let open R in let u2 = pack_universe (Uv_Succ (pack_universe (Uv_Succ (pack_universe Uv_Zero)))) in let t = pack_ln (Tv_UInst (pack_fv eq2_qn) [u2]) in let t = pack_ln (Tv_App t (pack_ln (Tv_FVar (pack_fv vprop_lid)), Q_Implicit)) in let t = pack_ln (Tv_App t (t1, Q_Explicit)) in let t = pack_ln (Tv_App t (t2, Q_Explicit)) in t
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.return_stt_atomic_lid
val return_stt_atomic_lid : Prims.list Prims.string
let return_stt_atomic_lid = mk_pulse_lib_core_lid "return_stt_atomic"
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 69, "end_line": 323, "start_col": 0, "start_line": 323 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t) let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit)) let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit)) let elim_exists_lid = mk_pulse_lib_core_lid "elim_exists" let intro_exists_lid = mk_pulse_lib_core_lid "intro_exists" let intro_exists_erased_lid = mk_pulse_lib_core_lid "intro_exists_erased" let mk_exists (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_forall (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv forall_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_elim_exists (u:R.universe) (a p:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv elim_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_intro_exists (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let mk_intro_exists_erased (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_erased_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let while_lid = ["Pulse"; "Lib"; "WhileLoop"; "while_loop"] let mk_while (inv cond body:R.term) : R.term = let t = R.pack_ln (R.Tv_FVar (R.pack_fv while_lid)) in let t = R.pack_ln (R.Tv_App t (inv, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (cond, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (body, R.Q_Explicit)) let vprop_eq_tm t1 t2 = let open R in let u2 = pack_universe (Uv_Succ (pack_universe (Uv_Succ (pack_universe Uv_Zero)))) in let t = pack_ln (Tv_UInst (pack_fv eq2_qn) [u2]) in let t = pack_ln (Tv_App t (pack_ln (Tv_FVar (pack_fv vprop_lid)), Q_Implicit)) in let t = pack_ln (Tv_App t (t1, Q_Explicit)) in let t = pack_ln (Tv_App t (t2, Q_Explicit)) in t let emp_inames_tm : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv emp_inames_lid)) let all_inames_tm : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv all_inames_lid)) let add_inv_tm (p is i : R.term) : R.term = let h = R.pack_ln (R.Tv_FVar (R.pack_fv add_inv_lid)) in R.mk_app h [im p; ex is; ex i] let remove_inv_tm (p is i : R.term) : R.term = let h = R.pack_ln (R.Tv_FVar (R.pack_fv remove_inv_lid)) in R.mk_app h [im p; ex is; ex i] let non_informative_witness_lid = mk_pulse_lib_core_lid "non_informative_witness" let non_informative_witness_rt (u:R.universe) (a:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv non_informative_witness_lid) [u]) in let t = pack_ln (Tv_App t (a, Q_Explicit)) in t let stt_vprop_equiv_fv = R.pack_fv (mk_pulse_lib_core_lid "vprop_equiv") let stt_vprop_equiv_tm = R.pack_ln (R.Tv_FVar stt_vprop_equiv_fv) let stt_vprop_equiv (t1 t2:R.term) = let open R in let t = pack_ln (Tv_App stt_vprop_equiv_tm (t1, Q_Explicit)) in pack_ln (Tv_App t (t2, Q_Explicit)) let return_stt_lid = mk_pulse_lib_core_lid "return_stt"
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let return_stt_atomic_lid =
mk_pulse_lib_core_lid "return_stt_atomic"
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.stt_vprop_equiv_fv
val stt_vprop_equiv_fv : FStar.Stubs.Reflection.Types.fv
let stt_vprop_equiv_fv = R.pack_fv (mk_pulse_lib_core_lid "vprop_equiv")
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 313, "start_col": 0, "start_line": 312 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t) let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit)) let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit)) let elim_exists_lid = mk_pulse_lib_core_lid "elim_exists" let intro_exists_lid = mk_pulse_lib_core_lid "intro_exists" let intro_exists_erased_lid = mk_pulse_lib_core_lid "intro_exists_erased" let mk_exists (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_forall (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv forall_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_elim_exists (u:R.universe) (a p:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv elim_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_intro_exists (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let mk_intro_exists_erased (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_erased_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let while_lid = ["Pulse"; "Lib"; "WhileLoop"; "while_loop"] let mk_while (inv cond body:R.term) : R.term = let t = R.pack_ln (R.Tv_FVar (R.pack_fv while_lid)) in let t = R.pack_ln (R.Tv_App t (inv, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (cond, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (body, R.Q_Explicit)) let vprop_eq_tm t1 t2 = let open R in let u2 = pack_universe (Uv_Succ (pack_universe (Uv_Succ (pack_universe Uv_Zero)))) in let t = pack_ln (Tv_UInst (pack_fv eq2_qn) [u2]) in let t = pack_ln (Tv_App t (pack_ln (Tv_FVar (pack_fv vprop_lid)), Q_Implicit)) in let t = pack_ln (Tv_App t (t1, Q_Explicit)) in let t = pack_ln (Tv_App t (t2, Q_Explicit)) in t let emp_inames_tm : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv emp_inames_lid)) let all_inames_tm : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv all_inames_lid)) let add_inv_tm (p is i : R.term) : R.term = let h = R.pack_ln (R.Tv_FVar (R.pack_fv add_inv_lid)) in R.mk_app h [im p; ex is; ex i] let remove_inv_tm (p is i : R.term) : R.term = let h = R.pack_ln (R.Tv_FVar (R.pack_fv remove_inv_lid)) in R.mk_app h [im p; ex is; ex i] let non_informative_witness_lid = mk_pulse_lib_core_lid "non_informative_witness" let non_informative_witness_rt (u:R.universe) (a:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv non_informative_witness_lid) [u]) in let t = pack_ln (Tv_App t (a, Q_Explicit)) in t
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
FStar.Stubs.Reflection.Types.fv
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let stt_vprop_equiv_fv =
R.pack_fv (mk_pulse_lib_core_lid "vprop_equiv")
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_ghost
val mk_ghost : t: FStar.Stubs.Reflection.Types.typ -> FStar.Stubs.Reflection.V2.Data.comp_view
let mk_ghost t = R.C_GTotal t
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 29, "end_line": 212, "start_col": 0, "start_line": 212 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.typ -> FStar.Stubs.Reflection.V2.Data.comp_view
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.V2.Data.C_GTotal", "FStar.Stubs.Reflection.V2.Data.comp_view" ]
[]
false
false
false
true
false
let mk_ghost t =
R.C_GTotal t
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.while_lid
val while_lid : Prims.list Prims.string
let while_lid = ["Pulse"; "Lib"; "WhileLoop"; "while_loop"]
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 59, "end_line": 275, "start_col": 0, "start_line": 275 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t) let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit)) let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit)) let elim_exists_lid = mk_pulse_lib_core_lid "elim_exists" let intro_exists_lid = mk_pulse_lib_core_lid "intro_exists" let intro_exists_erased_lid = mk_pulse_lib_core_lid "intro_exists_erased" let mk_exists (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_forall (u:R.universe) (a p:R.term) = let t = R.pack_ln (R.Tv_UInst (R.pack_fv forall_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_elim_exists (u:R.universe) (a p:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv elim_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) let mk_intro_exists (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit)) let mk_intro_exists_erased (u:R.universe) (a p:R.term) (e:R.term) : R.term = let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_erased_lid) [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (e, R.Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let while_lid =
["Pulse"; "Lib"; "WhileLoop"; "while_loop"]
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_erased
val mk_erased (u: R.universe) (t: R.term) : R.term
val mk_erased (u: R.universe) (t: R.term) : R.term
let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 237, "start_col": 0, "start_line": 235 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u188: FStar.Stubs.Reflection.Types.universe -> t: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.erased_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_erased (u: R.universe) (t: R.term) : R.term =
let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_arrow_with_name
val mk_arrow_with_name (s: RT.pp_name_t) (f: arrow_dom) (out: R.term) : R.term
val mk_arrow_with_name (s: RT.pp_name_t) (f: arrow_dom) (out: R.term) : R.term
let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out)))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 78, "end_line": 224, "start_col": 0, "start_line": 222 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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: FStar.Reflection.Typing.pp_name_t -> f: Pulse.Reflection.Util.arrow_dom -> out: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Reflection.Typing.pp_name_t", "Pulse.Reflection.Util.arrow_dom", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_Arrow", "Pulse.Reflection.Util.binder_of_t_q_s", "FStar.Stubs.Reflection.V2.Builtins.pack_comp", "Pulse.Reflection.Util.mk_total" ]
[]
false
false
false
true
false
let mk_arrow_with_name (s: RT.pp_name_t) (f: arrow_dom) (out: R.term) : R.term =
let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out)))
false
Pulse.Reflection.Util.fst
Pulse.Reflection.Util.mk_reveal
val mk_reveal (u: R.universe) (t e: R.term) : R.term
val mk_reveal (u: R.universe) (t e: R.term) : R.term
let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit))
{ "file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 242, "start_col": 0, "start_line": 239 }
(* Copyright 2023 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 Pulse.Reflection.Util module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing module RU = Pulse.RuntimeUtils open FStar.List.Tot let u_two = RT.(u_succ (u_succ u_zero)) let u_max_two u = (RT.u_max u_two u) let pulse_lib_core = ["Pulse"; "Lib"; "Core"] let mk_pulse_lib_core_lid s = pulse_lib_core@[s] let tun = R.pack_ln R.Tv_Unknown let unit_lid = R.unit_lid let bool_lid = R.bool_lid let int_lid = R.int_lid let erased_lid = ["FStar"; "Ghost"; "erased"] let hide_lid = ["FStar"; "Ghost"; "hide"] let reveal_lid = ["FStar"; "Ghost"; "reveal"] let vprop_lid = mk_pulse_lib_core_lid "vprop" let vprop_fv = R.pack_fv vprop_lid let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv) let unit_fv = R.pack_fv unit_lid let unit_tm = R.pack_ln (R.Tv_FVar unit_fv) let bool_fv = R.pack_fv bool_lid let bool_tm = R.pack_ln (R.Tv_FVar bool_fv) let nat_lid = ["Prims"; "nat"] let nat_fv = R.pack_fv nat_lid let nat_tm = R.pack_ln (R.Tv_FVar nat_fv) let szt_lid = ["FStar"; "SizeT"; "t"] let szt_fv = R.pack_fv szt_lid let szt_tm = R.pack_ln (R.Tv_FVar szt_fv) let szv_lid = ["FStar"; "SizeT"; "v"] let szv_fv = R.pack_fv szv_lid let szv_tm = R.pack_ln (R.Tv_FVar szv_fv) let seq_lid = ["FStar"; "Seq"; "Base"; "seq"] let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"] let tot_lid = ["Prims"; "Tot"] (* The "plicities" *) let ex t : R.argv = (t, R.Q_Explicit) let im t : R.argv = (t, R.Q_Implicit) let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"] let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"] let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"] let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Explicit)) in pack_ln (Tv_App t (a2, Q_Explicit)) let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in let t = pack_ln (Tv_App t (a1, Q_Implicit)) in let t = pack_ln (Tv_App t (a2, Q_Implicit)) in pack_ln (Tv_App t (e, Q_Explicit)) let true_tm = R.pack_ln (R.Tv_Const (R.C_True)) let false_tm = R.pack_ln (R.Tv_Const (R.C_False)) let inv_lid = mk_pulse_lib_core_lid "inv" let emp_lid = mk_pulse_lib_core_lid "emp" let inames_lid = mk_pulse_lib_core_lid "inames" let star_lid = mk_pulse_lib_core_lid "op_Star_Star" let mk_star (l r:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv star_lid)) in let t = pack_ln (Tv_App t (l, Q_Explicit)) in pack_ln (Tv_App t (r, Q_Explicit)) let pure_lid = mk_pulse_lib_core_lid "pure" let exists_lid = mk_pulse_lib_core_lid "op_exists_Star" let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"] let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s] let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star" let args_of (tms:list R.term) = List.Tot.map (fun x -> x, R.Q_Explicit) tms let mk_pure (p:R.term) : R.term = let open R in let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in pack_ln (Tv_App t (p, Q_Explicit)) let uzero = R.pack_universe (R.Uv_Zero) let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"] let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s] let mk_squash (u:R.universe) (ty:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in pack_ln (Tv_App t (ty, Q_Explicit)) let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in let t = pack_ln (Tv_App t (ty, Q_Implicit)) in let t = pack_ln (Tv_App t (e1, Q_Explicit)) in pack_ln (Tv_App t (e2, Q_Explicit)) let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit" let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit" let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit" let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term = let open R in let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in let t = pack_ln (Tv_App t (t, Q_Explicit)) in let t = pack_ln (Tv_App t (pre, Q_Explicit)) in pack_ln (Tv_App t (post, Q_Explicit)) let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames" let all_inames_lid = mk_pulse_lib_core_lid "all_inames" let add_inv_lid = mk_pulse_lib_core_lid "add_inv" let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv" let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure" //the thunked, value-type counterpart of the effect STT let stt_lid = mk_pulse_lib_core_lid "stt" let stt_fv = R.pack_fv stt_lid let stt_tm = R.pack_ln (R.Tv_FVar stt_fv) let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term = let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic" let stt_atomic_fv = R.pack_fv stt_atomic_lid let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv) let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable" let stt_unobservable_fv = R.pack_fv stt_unobservable_lid let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv) let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) = let head = stt_atomic_fv in let t = R.pack_ln (R.Tv_UInst head [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost" let stt_ghost_fv = R.pack_fv stt_ghost_lid let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv) let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) = let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in R.pack_ln (R.Tv_App t (post, R.Q_Explicit)) let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term) (posts_equiv:RT.equiv g post1 post2) : RT.equiv g (mk_stt_ghost_comp u a pre post1) (mk_stt_ghost_comp u a pre post2) = let open R in let open RT in let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in Rel_ctxt g post1 post2 (Ctxt_app_arg t Q_Explicit Ctxt_hole) posts_equiv let mk_total t = R.C_Total t let mk_ghost t = R.C_GTotal t let binder_of_t_q t q = RT.binder_of_t_q t q let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q let bound_var i : R.term = RT.bound_var i let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i))) let arrow_dom = (R.term & R.aqualv) let mk_arrow (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out))) let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out))) let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term = let ty, q = f in R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out))) let mk_abs ty qual t : R.term = RT.mk_abs ty qual t let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t) let mk_abs_with_name_and_range s r ty qual t : R.term = let b = (binder_of_t_q_s ty qual s) in let b = RU.binder_set_range b r in R.pack_ln (R.Tv_Abs b t) let mk_erased (u:R.universe) (t:R.term) : R.term = let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in R.pack_ln (R.Tv_App hd (t, R.Q_Explicit))
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Reflection.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection", "short_module": null }, { "abbrev": 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
u194: FStar.Stubs.Reflection.Types.universe -> t: FStar.Stubs.Reflection.Types.term -> e: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "FStar.Stubs.Reflection.V2.Data.Tv_UInst", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.reveal_lid", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_reveal (u: R.universe) (t e: R.term) : R.term =
let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in R.pack_ln (R.Tv_App hd (e, R.Q_Explicit))
false