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
Trees.fst
Trees.rotate_right
val rotate_right (#a: Type) (r: tree a) : option (tree a)
val rotate_right (#a: Type) (r: tree a) : option (tree a)
let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 171, "start_col": 0, "start_line": 168 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Trees.tree a -> FStar.Pervasives.Native.option (Trees.tree a)
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "FStar.Pervasives.Native.Some", "Trees.Node", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let rotate_right (#a: Type) (r: tree a) : option (tree a) =
match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None
false
Trees.fst
Trees.bst_search
val bst_search (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : option a
val bst_search (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : option a
let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 69, "start_col": 0, "start_line": 62 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.bst a cmp -> key: a -> FStar.Pervasives.Native.option a
Prims.Tot
[ "total" ]
[]
[ "Trees.cmp", "Trees.bst", "FStar.Pervasives.Native.None", "Trees.tree", "Prims.op_LessThan", "Trees.bst_search", "Prims.bool", "Prims.op_GreaterThan", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.option", "Prims.int" ]
[ "recursion" ]
false
false
false
false
false
let rec bst_search (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : option a =
match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data
false
Trees.fst
Trees.append_left
val append_left (#a: Type) (x: tree a) (v: a) : tree a
val append_left (#a: Type) (x: tree a) (v: a) : tree a
let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 58, "end_line": 85, "start_col": 0, "start_line": 82 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Trees.tree a -> v: a -> Trees.tree a
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "Trees.Node", "Trees.Leaf", "Trees.append_left" ]
[ "recursion" ]
false
false
false
true
false
let rec append_left (#a: Type) (x: tree a) (v: a) : tree a =
match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right
false
Trees.fst
Trees.rotate_left
val rotate_left (#a: Type) (r: tree a) : option (tree a)
val rotate_left (#a: Type) (r: tree a) : option (tree a)
let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 166, "start_col": 0, "start_line": 163 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Trees.tree a -> FStar.Pervasives.Native.option (Trees.tree a)
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "FStar.Pervasives.Native.Some", "Trees.Node", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let rotate_left (#a: Type) (r: tree a) : option (tree a) =
match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None
false
TwoLockQueue.fst
TwoLockQueue.queue_invariant
val queue_invariant : head: TwoLockQueue.q_ptr a -> tail: TwoLockQueue.q_ptr a -> Steel.Effect.Common.vprop
let queue_invariant (#a:_) ([@@@smt_fallback]head:q_ptr a) ([@@@smt_fallback] tail:q_ptr a) = h_exists (fun (h:Q.t a) -> h_exists (fun (t:Q.t a) -> ghost_pts_to head.ghost half h `star` ghost_pts_to tail.ghost half t `star` Q.queue h t))
{ "file_name": "share/steel/examples/steel/TwoLockQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 17, "end_line": 113, "start_col": 0, "start_line": 108 }
module TwoLockQueue open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock module L = FStar.List.Tot module U = Steel.Utils module Q = Queue /// This module provides an implementation of Michael and Scott's two lock queue, using the /// abstract interface for queues provided in Queue.fsti. /// This implementation allows an enqueue and a dequeue operation to safely operate in parallel. /// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation, /// ensuring that at most one enqueue (resp. dequeue) is happening at any time /// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue #push-options "--ide_id_info_off" /// Adding the definition of the vprop equivalence to the context, for proof purposes let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) = Classical.forall_intro_2 reveal_equiv (* Some wrappers to reduce clutter in the code *) [@@__reduce__] let full = full_perm [@@__reduce__] let half = half_perm full (* Wrappers around fst and snd to avoid overnormalization. TODO: The frame inference tactic should not normalize fst and snd *) let fst x = fst x let snd x = snd x (* Some wrappers around Steel functions which are easier to use inside this module *) let ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1}) (x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r p x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1) = let _ = ghost_gather_pt #a #u #p0 #p1 r in () let rewrite #u (p q:vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) = rewrite_slprop p q (fun _ -> reveal_equiv p q) let elim_pure (#p:prop) #u () : SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) = let _ = Steel.Effect.Atomic.elim_pure p in () let open_exists (#a:Type) (#opened_invariants:_) (#p:a -> vprop) (_:unit) : SteelGhostT (Ghost.erased a) opened_invariants (h_exists p) (fun r -> p (reveal r)) = let v : erased a = witness_exists () in v (*** Queue invariant ***) /// The invariant associated to the lock. Basically a variant of the /// Owicki-Gries invariant, but applied to queues [@@__reduce__] let lock_inv #a (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) = h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) let intro_lock_inv #a #u (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (fun _ -> lock_inv ptr ghost) = assert_spinoff (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) == lock_inv ptr ghost); rewrite_slprop (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (lock_inv _ _) (fun _ -> ()) /// The type of a queue pointer. /// Contains the concrete pointer [ptr], the pointer to ghost state [ghost], /// and a lock [lock] protecting the invariant relating the concrete and ghost states noeq type q_ptr (a:Type) = { ptr : ref (Q.t a); ghost: ghost_ref (Q.t a); lock: lock (lock_inv ptr ghost); } /// The global queue invariant, which will be shared by the enqueuer and the dequeuer. /// Again, inspired by the Owicki-Gries counter: It contains half the permission for the ghost /// state of the enqueuer and dequeuer, while ensuring that the concrete queue always remains
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Queue.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "TwoLockQueue.fst" }
[ { "abbrev": true, "full_module": "Queue", "short_module": "Q" }, { "abbrev": true, "full_module": "Steel.Utils", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": 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
head: TwoLockQueue.q_ptr a -> tail: TwoLockQueue.q_ptr a -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "TwoLockQueue.q_ptr", "Steel.Effect.Atomic.h_exists", "Queue.Def.t", "Steel.Effect.Common.star", "Steel.Reference.ghost_pts_to", "TwoLockQueue.__proj__Mkq_ptr__item__ghost", "TwoLockQueue.half", "Queue.queue", "Steel.Effect.Common.vprop" ]
[]
false
false
false
true
false
let queue_invariant (#a: _) ([@@@ smt_fallback]head [@@@ smt_fallback]tail: q_ptr a) =
h_exists (fun (h: Q.t a) -> h_exists (fun (t: Q.t a) -> ((ghost_pts_to head.ghost half h) `star` (ghost_pts_to tail.ghost half t)) `star` (Q.queue h t)))
false
Trees.fst
Trees.insert_bst_preserves_forall_keys
val insert_bst_preserves_forall_keys (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) (cond: (a -> bool)) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond))
val insert_bst_preserves_forall_keys (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) (cond: (a -> bool)) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond))
let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 57, "end_line": 127, "start_col": 0, "start_line": 110 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.bst a cmp -> key: a -> cond: (_: a -> Prims.bool) -> FStar.Pervasives.Lemma (requires Trees.forall_keys x cond /\ cond key) (ensures Trees.forall_keys (Trees.insert_bst cmp x key) cond)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.bst", "Prims.bool", "Trees.tree", "Prims.op_GreaterThanOrEqual", "Trees.insert_bst_preserves_forall_keys", "Prims.unit", "Prims.int", "Prims.l_and", "Prims.b2t", "Trees.forall_keys", "Prims.squash", "Trees.insert_bst", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec insert_bst_preserves_forall_keys (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) (cond: (a -> bool)) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) =
match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond
false
Trees.fst
Trees.height
val height (#a: Type) (x: tree a) : nat
val height (#a: Type) (x: tree a) : nat
let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 27, "end_line": 78, "start_col": 0, "start_line": 73 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Trees.tree a -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "Prims.op_GreaterThan", "Trees.height", "Prims.op_Addition", "Prims.bool", "Prims.nat" ]
[ "recursion" ]
false
false
false
true
false
let rec height (#a: Type) (x: tree a) : nat =
match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1
false
Trees.fst
Trees.insert_bst_preserves_bst
val insert_bst_preserves_bst (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : Lemma (is_bst cmp (insert_bst cmp x key))
val insert_bst_preserves_bst (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : Lemma (is_bst cmp (insert_bst cmp x key))
let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 146, "start_col": 0, "start_line": 129 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.bst a cmp -> key: a -> FStar.Pervasives.Lemma (ensures Trees.is_bst cmp (Trees.insert_bst cmp x key))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.bst", "Trees.tree", "Prims.op_GreaterThanOrEqual", "Trees.insert_bst_preserves_bst", "Prims.unit", "Trees.insert_bst_preserves_forall_keys", "Trees.key_left", "Prims.bool", "Trees.key_right", "Prims.int", "Prims.l_True", "Prims.squash", "Prims.b2t", "Trees.is_bst", "Trees.insert_bst", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec insert_bst_preserves_bst (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : Lemma (is_bst cmp (insert_bst cmp x key)) =
match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then (insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key) else (insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key)
false
Trees.fst
Trees.rotate_right_left
val rotate_right_left (#a: Type) (r: tree a) : option (tree a)
val rotate_right_left (#a: Type) (r: tree a) : option (tree a)
let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 176, "start_col": 0, "start_line": 173 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Trees.tree a -> FStar.Pervasives.Native.option (Trees.tree a)
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "FStar.Pervasives.Native.Some", "Trees.Node", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let rotate_right_left (#a: Type) (r: tree a) : option (tree a) =
match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None
false
Trees.fst
Trees.rotate_left_right
val rotate_left_right (#a: Type) (r: tree a) : option (tree a)
val rotate_left_right (#a: Type) (r: tree a) : option (tree a)
let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 181, "start_col": 0, "start_line": 178 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Trees.tree a -> FStar.Pervasives.Native.option (Trees.tree a)
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "FStar.Pervasives.Native.Some", "Trees.Node", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let rotate_left_right (#a: Type) (r: tree a) : option (tree a) =
match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None
false
Trees.fst
Trees.append_right
val append_right (#a: Type) (x: tree a) (v: a) : tree a
val append_right (#a: Type) (x: tree a) (v: a) : tree a
let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v)
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 59, "end_line": 90, "start_col": 0, "start_line": 87 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Trees.tree a -> v: a -> Trees.tree a
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "Trees.Node", "Trees.Leaf", "Trees.append_right" ]
[ "recursion" ]
false
false
false
true
false
let rec append_right (#a: Type) (x: tree a) (v: a) : tree a =
match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v)
false
Trees.fst
Trees.is_balanced
val is_balanced (#a: Type) (x: tree a) : bool
val is_balanced (#a: Type) (x: tree a) : bool
let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left)
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 156, "start_col": 0, "start_line": 150 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Trees.tree a -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "FStar.Math.Lib.abs", "Prims.op_Subtraction", "Trees.height", "Trees.is_balanced", "Prims.bool" ]
[ "recursion" ]
false
false
false
true
false
let rec is_balanced (#a: Type) (x: tree a) : bool =
match x with | Leaf -> true | Node data left right -> M.abs (height right - height left) <= 1 && is_balanced (right) && is_balanced (left)
false
Trees.fst
Trees.insert_bst
val insert_bst (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : tree a
val insert_bst (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : tree a
let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 108, "start_col": 0, "start_line": 97 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.bst a cmp -> key: a -> Trees.tree a
Prims.Tot
[ "total" ]
[]
[ "Trees.cmp", "Trees.bst", "Trees.Node", "Trees.Leaf", "Trees.tree", "Prims.op_GreaterThanOrEqual", "Trees.insert_bst", "Prims.bool", "Prims.int" ]
[ "recursion" ]
false
false
false
false
false
let rec insert_bst (#a: Type) (cmp: cmp a) (x: bst a cmp) (key: a) : tree a =
match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then let new_left = insert_bst cmp left key in Node data new_left right else let new_right = insert_bst cmp right key in Node data left new_right
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_constants
val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants}
val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants}
let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 70, "start_col": 0, "start_line": 66 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants:
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Buffer.glbuffer Lib.IntTypes.size_t 4ul {Lib.Buffer.recallable b /\ Lib.Buffer.witnessed b Spec.Chacha20.chacha20_constants}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Lib.IntTypes.size_t", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.UInt32.__uint_to_t", "Prims.l_and", "Lib.Buffer.recallable", "Lib.Buffer.CONST", "Lib.Buffer.witnessed", "Spec.Chacha20.chacha20_constants", "Prims.list", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.Cons", "Hacl.Spec.Chacha20.Vec.c0", "Hacl.Spec.Chacha20.Vec.c1", "Hacl.Spec.Chacha20.Vec.c2", "Hacl.Spec.Chacha20.Vec.c3", "Prims.Nil" ]
[]
false
false
false
false
false
let chacha20_constants =
[@@ inline_let ]let l = [Spec.c0; Spec.c1; Spec.c2; Spec.c3] in assert_norm (List.Tot.length l == 4); createL_global l
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.lemma_ecdsa_sign_s
val lemma_ecdsa_sign_s (k kinv r d_a m:S.qelem) : Lemma (requires from_qmont kinv == to_qmont (S.qinv k)) (ensures (let s = (from_qmont m + from_qmont (r * d_a)) % S.order in from_qmont (kinv * s) == S.qmul (S.qinv k) (S.qadd m (S.qmul r d_a))))
val lemma_ecdsa_sign_s (k kinv r d_a m:S.qelem) : Lemma (requires from_qmont kinv == to_qmont (S.qinv k)) (ensures (let s = (from_qmont m + from_qmont (r * d_a)) % S.order in from_qmont (kinv * s) == S.qmul (S.qinv k) (S.qadd m (S.qmul r d_a))))
let lemma_ecdsa_sign_s k kinv r d_a m = let s = (from_qmont m + from_qmont (r * d_a)) % S.order in calc (==) { // s = (m * qmont_R_inv % S.order + (r * d_a * qmont_R_inv) % S.order) % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_l (r * d_a) qmont_R_inv S.order } (m * qmont_R_inv % S.order + (S.qmul r d_a * qmont_R_inv) % S.order) % S.order; (==) { qmont_add_lemma m (S.qmul r d_a) } (S.qadd m (S.qmul r d_a)) * qmont_R_inv % S.order; (==) { } from_qmont (S.qadd m (S.qmul r d_a)); }; calc (==) { (kinv * s * qmont_R_inv) % S.order; (==) { lemma_abc_is_acb kinv s qmont_R_inv } (kinv * qmont_R_inv * s) % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_l (kinv * qmont_R_inv) s S.order } ((kinv * qmont_R_inv % S.order) * s) % S.order; (==) { } to_qmont (S.qinv k) * s % S.order; (==) { qmont_cancel_lemma2 (S.qinv k) (S.qadd m (S.qmul r d_a)) } (S.qinv k * (S.qadd m (S.qmul r d_a))) % S.order; }
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 376, "start_col": 0, "start_line": 354 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; } //-------------------------- let lemma_to_from_qmont_id a = mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a let lemma_from_to_qmont_id a = mul_qmont_R_and_R_inv_is_one (); Math.Lemmas.swap_mul qmont_R qmont_R_inv; lemma_from_to_mont_id_gen S.order qmont_R qmont_R_inv a let qmont_add_lemma a b = mont_add_lemma_gen S.order qmont_R_inv a b let qmont_mul_lemma a b = mont_mul_lemma_gen S.order qmont_R_inv a b let qmont_inv_lemma k = assert_norm (M.pow_mod_ #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); M.pow_mod_def #S.order qmont_R_inv (S.order - 2); assert (M.pow_mod #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); lemma_mont_inv_gen S.order qmont_R qmont_R_inv k; assert (M.pow_mod #S.order (k * qmont_R_inv % S.order) (S.order - 2) == M.pow_mod #S.order k (S.order - 2) * qmont_R % S.order); assert (S.qinv (k * qmont_R_inv % S.order) == S.qinv k * qmont_R % S.order) val qmont_cancel_lemma1: a:S.qelem -> b:S.qelem -> Lemma ((a * qmont_R % S.order * b * qmont_R_inv) % S.order = a * b % S.order) let qmont_cancel_lemma1 a b = mul_qmont_R_and_R_inv_is_one (); mont_cancel_lemma_gen S.order qmont_R qmont_R_inv a b val qmont_cancel_lemma2: a:S.qelem -> b:S.qelem -> Lemma (to_qmont a * from_qmont b % S.order = a * b % S.order) let qmont_cancel_lemma2 a b = calc (==) { to_qmont a * from_qmont b % S.order; (==) { } (a * qmont_R % S.order * (b * qmont_R_inv % S.order)) % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * qmont_R % S.order) (b * qmont_R_inv) S.order } (a * qmont_R % S.order * (b * qmont_R_inv)) % S.order; (==) { Math.Lemmas.paren_mul_right (a * qmont_R % S.order) b qmont_R_inv } (a * qmont_R % S.order * b * qmont_R_inv) % S.order; (==) { qmont_cancel_lemma1 a b } a * b % S.order; } let qmont_inv_mul_lemma s sinv b = let s_mont = from_qmont s in let b_mont = from_qmont b in calc (==) { (sinv * b_mont * qmont_R_inv) % S.order; (==) { lemma_from_to_qmont_id sinv } (S.qinv s_mont * qmont_R % S.order * b_mont * qmont_R_inv) % S.order; (==) { qmont_cancel_lemma1 (S.qinv s_mont) b_mont } S.qinv s_mont * b_mont % S.order; (==) { qmont_inv_lemma s } (S.qinv s * qmont_R % S.order * (b * qmont_R_inv % S.order)) % S.order; (==) { qmont_cancel_lemma2 (S.qinv s) b } S.qinv s * b % S.order; }
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": 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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Spec.P256.PointOps.qelem -> kinv: Spec.P256.PointOps.qelem -> r: Spec.P256.PointOps.qelem -> d_a: Spec.P256.PointOps.qelem -> m: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (requires Hacl.Spec.P256.Montgomery.from_qmont kinv == Hacl.Spec.P256.Montgomery.to_qmont (Spec.P256.PointOps.qinv k)) (ensures (let s = (Hacl.Spec.P256.Montgomery.from_qmont m + Hacl.Spec.P256.Montgomery.from_qmont (r * d_a) ) % Spec.P256.PointOps.order in Hacl.Spec.P256.Montgomery.from_qmont (kinv * s) == Spec.P256.PointOps.qmul (Spec.P256.PointOps.qinv k) (Spec.P256.PointOps.qadd m (Spec.P256.PointOps.qmul r d_a))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "Spec.P256.PointOps.order", "Spec.P256.PointOps.qinv", "Spec.P256.PointOps.qadd", "Spec.P256.PointOps.qmul", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Hacl.Spec.P256.Montgomery.to_qmont", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.P256.Montgomery.lemma_abc_is_acb", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Hacl.Spec.P256.Montgomery.qmont_cancel_lemma2", "Prims.op_Addition", "Hacl.Spec.P256.Montgomery.from_qmont", "Hacl.Spec.P256.Montgomery.qmont_add_lemma" ]
[]
false
false
true
false
false
let lemma_ecdsa_sign_s k kinv r d_a m =
let s = (from_qmont m + from_qmont (r * d_a)) % S.order in calc ( == ) { (m * qmont_R_inv % S.order + ((r * d_a) * qmont_R_inv) % S.order) % S.order; ( == ) { Math.Lemmas.lemma_mod_mul_distr_l (r * d_a) qmont_R_inv S.order } (m * qmont_R_inv % S.order + (S.qmul r d_a * qmont_R_inv) % S.order) % S.order; ( == ) { qmont_add_lemma m (S.qmul r d_a) } (S.qadd m (S.qmul r d_a)) * qmont_R_inv % S.order; ( == ) { () } from_qmont (S.qadd m (S.qmul r d_a)); }; calc ( == ) { ((kinv * s) * qmont_R_inv) % S.order; ( == ) { lemma_abc_is_acb kinv s qmont_R_inv } ((kinv * qmont_R_inv) * s) % S.order; ( == ) { Math.Lemmas.lemma_mod_mul_distr_l (kinv * qmont_R_inv) s S.order } ((kinv * qmont_R_inv % S.order) * s) % S.order; ( == ) { () } to_qmont (S.qinv k) * s % S.order; ( == ) { qmont_cancel_lemma2 (S.qinv k) (S.qadd m (S.qmul r d_a)) } (S.qinv k * (S.qadd m (S.qmul r d_a))) % S.order; }
false
Spec.Hash.Lemmas.fst
Spec.Hash.Lemmas.update_multi_associative
val update_multi_associative (a: hash_alg{not (is_blake a)}) (h: words_state a) (input1: bytes) (input2: bytes): Lemma (requires S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0) (ensures ( let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi a (update_multi a h () input1) () input2 == update_multi a h () input))
val update_multi_associative (a: hash_alg{not (is_blake a)}) (h: words_state a) (input1: bytes) (input2: bytes): Lemma (requires S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0) (ensures ( let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi a (update_multi a h () input1) () input2 == update_multi a h () input))
let update_multi_associative (a: hash_alg{not (is_blake a)}) (h: words_state a) (input1: bytes) (input2: bytes): Lemma (requires S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0) (ensures ( let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi a (update_multi a h () input1) () input2 == update_multi a h () input)) = match a with | MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> Lib.UpdateMulti.update_multi_associative (block_length a) (Spec.Agile.Hash.update a) h input1 input2 | SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> let rateInBytes = rate a /8 in let f = Spec.SHA3.absorb_inner rateInBytes in let input = input1 `S.append` input2 in assert (input1 `S.equal` S.slice input 0 (S.length input1)); assert (input2 `S.equal` S.slice input (S.length input1) (S.length input)); Lib.Sequence.Lemmas.repeat_blocks_multi_split (block_length a) (S.length input1) input f h
{ "file_name": "specs/lemmas/Spec.Hash.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 94, "end_line": 73, "start_col": 0, "start_line": 52 }
module Spec.Hash.Lemmas module S = FStar.Seq open Lib.IntTypes open Spec.Agile.Hash open Spec.Hash.Definitions friend Spec.Agile.Hash (** Lemmas about the behavior of update_multi / update_last *) #push-options "--fuel 0 --ifuel 1 --z3rlimit 50" let update_multi_zero a h = match a with | MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h | SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> let rateInBytes = rate a / 8 in let f = Spec.SHA3.absorb_inner rateInBytes in Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h; let nb = 0 / rateInBytes in Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h let update_multi_zero_blake a prevlen h = Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h #pop-options #push-options "--fuel 1" let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma (ensures (update_multi a h () input) == (update a h input)) = let h1 = update_multi a h () input in assert(h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input); if S.length input = 0 then begin assert(h1 == h) end else begin let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in let h2 = update a h block in assert(rem `Seq.equal` Seq.empty); assert(block `Seq.equal` input); let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in assert(h1 == h3) end #pop-options
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Spec.Hash.Lemmas.fst" }
[ { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": 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
a: Spec.Hash.Definitions.hash_alg{Prims.op_Negation (Spec.Hash.Definitions.is_blake a)} -> h: Spec.Hash.Definitions.words_state a -> input1: Spec.Hash.Definitions.bytes -> input2: Spec.Hash.Definitions.bytes -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length input1 % Spec.Hash.Definitions.block_length a == 0 /\ FStar.Seq.Base.length input2 % Spec.Hash.Definitions.block_length a == 0) (ensures (let input = FStar.Seq.Base.append input1 input2 in FStar.Seq.Base.length input % Spec.Hash.Definitions.block_length a == 0 /\ Spec.Agile.Hash.update_multi a (Spec.Agile.Hash.update_multi a h () input1) () input2 == Spec.Agile.Hash.update_multi a h () input))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Prims.op_Negation", "Spec.Hash.Definitions.is_blake", "Spec.Hash.Definitions.words_state", "Spec.Hash.Definitions.bytes", "Lib.UpdateMulti.update_multi_associative", "Spec.Hash.Definitions.block_length", "Spec.Agile.Hash.update", "Lib.Sequence.Lemmas.repeat_blocks_multi_split", "Lib.IntTypes.uint8", "Spec.SHA3.state", "FStar.Seq.Base.length", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "FStar.Seq.Base.seq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.Seq.Base.append", "Lib.Sequence.lseq", "Lib.IntTypes.U64", "Spec.SHA3.absorb_inner", "Prims.int", "Prims.op_Division", "Spec.Hash.Definitions.rate", "Prims.l_and", "Prims.eq2", "Prims.op_Modulus", "Prims.squash", "Spec.Agile.Hash.update_multi", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let update_multi_associative (a: hash_alg{not (is_blake a)}) (h: words_state a) (input1 input2: bytes) : Lemma (requires S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0) (ensures (let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi a (update_multi a h () input1) () input2 == update_multi a h () input)) =
match a with | MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> Lib.UpdateMulti.update_multi_associative (block_length a) (Spec.Agile.Hash.update a) h input1 input2 | SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> let rateInBytes = rate a / 8 in let f = Spec.SHA3.absorb_inner rateInBytes in let input = input1 `S.append` input2 in assert (input1 `S.equal` (S.slice input 0 (S.length input1))); assert (input2 `S.equal` (S.slice input (S.length input1) (S.length input))); Lib.Sequence.Lemmas.repeat_blocks_multi_split (block_length a) (S.length input1) input f h
false
Trees.fst
Trees.rotate_left_right_bst
val rotate_left_right_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r)))
val rotate_left_right_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r)))
let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 48, "end_line": 250, "start_col": 0, "start_line": 230 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> FStar.Pervasives.Lemma (requires Trees.is_bst cmp r /\ Some? (Trees.rotate_left_right r)) (ensures Trees.is_bst cmp (Some?.v (Trees.rotate_left_right r)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.key_right", "Prims.unit", "Trees.forall_keys_trans", "Trees.key_left", "Trees.is_bst", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_left_right", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_left_right_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) =
match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y))
false
Trees.fst
Trees.rotate_left_bst
val rotate_left_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r)))
val rotate_left_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r)))
let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z)
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 60, "end_line": 198, "start_col": 0, "start_line": 192 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> FStar.Pervasives.Lemma (requires Trees.is_bst cmp r /\ Some? (Trees.rotate_left r)) (ensures Trees.is_bst cmp (Some?.v (Trees.rotate_left r)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Trees.forall_keys_trans", "Trees.key_left", "Prims.unit", "Prims._assert", "Prims.b2t", "Trees.is_bst", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_left", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_left_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) =
match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z)
false
Trees.fst
Trees.rotate_right_left_bst
val rotate_right_left_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r)))
val rotate_right_left_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r)))
let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 48, "end_line": 227, "start_col": 0, "start_line": 208 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> FStar.Pervasives.Lemma (requires Trees.is_bst cmp r /\ Some? (Trees.rotate_right_left r)) (ensures Trees.is_bst cmp (Some?.v (Trees.rotate_right_left r)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.key_right", "Prims.unit", "Trees.forall_keys_trans", "Trees.key_left", "Trees.is_bst", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_right_left", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_right_left_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) =
match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y))
false
Trees.fst
Trees.rotate_right_left_key_right
val rotate_right_left_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root))
val rotate_right_left_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root))
let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 309, "start_col": 0, "start_line": 299 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_right cmp root) /\ Some? (Trees.rotate_right_left r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_right_left r)) (Trees.key_right cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.key_right", "Prims.unit", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_right_left", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_right_left_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) =
match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root))
false
Trees.fst
Trees.rotate_left_key_left
val rotate_left_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root))
val rotate_left_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root))
let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 260, "start_col": 0, "start_line": 254 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_left cmp root) /\ Some? (Trees.rotate_left r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_left r)) (Trees.key_left cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.Node", "Trees.key_left", "Prims.unit", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_left", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_left_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) =
match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root))
false
Trees.fst
Trees.insert_avl
val insert_avl (#a: Type) (cmp: cmp a) (x: tree a) (key: a) : tree a
val insert_avl (#a: Type) (cmp: cmp a) (x: tree a) (key: a) : tree a
let rec insert_avl (#a: Type) (cmp:cmp a) (x: tree a) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then ( let new_left = insert_avl cmp left key in let tmp = Node data new_left right in rebalance_avl tmp ) else ( let new_right = insert_avl cmp right key in let tmp = Node data left new_right in rebalance_avl tmp )
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 504, "start_col": 0, "start_line": 491 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) let rotate_left_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_left_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) (** Balancing operation for AVLs *) let rebalance_avl (#a: Type) (x: tree a) : tree a = match x with | Leaf -> x | Node data left right -> if is_balanced x then x else ( if height left - height right > 1 then ( let Node ldata lleft lright = left in if height lright > height lleft then ( match rotate_left_right x with | Some y -> y | _ -> x ) else ( match rotate_right x with | Some y -> y | _ -> x ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( match rotate_right_left x with | Some y -> y | _ -> x ) else ( match rotate_left x with | Some y -> y | _ -> x ) ) else ( x ) ) let rebalance_avl_proof (#a: Type) (cmp:cmp a) (x: tree a) (root:a) : Lemma (requires is_bst cmp x /\ ( match x with | Leaf -> True | Node data left right -> is_balanced left /\ is_balanced right /\ height left - height right <= 2 /\ height right - height left <= 2 ) ) (ensures is_avl cmp (rebalance_avl x) /\ (forall_keys x (key_left cmp root) ==> forall_keys (rebalance_avl x) (key_left cmp root)) /\ (forall_keys x (key_right cmp root) ==> forall_keys (rebalance_avl x) (key_right cmp root)) ) = match x with | Leaf -> () | Node data left right -> let x_f = rebalance_avl x in let Node f_data f_left f_right = x_f in if is_balanced x then () else ( if height left - height right > 1 then ( assert (height left = height right + 2); let Node ldata lleft lright = left in if height lright > height lleft then ( assert (height left = height lright + 1); rotate_left_right_bst cmp x; Classical.move_requires (rotate_left_right_key_left cmp x) root; Classical.move_requires (rotate_left_right_key_right cmp x) root; let Node y t2 t3 = lright in let Node x (Node z t1 (Node y t2 t3)) t4 = x in assert (f_data == y); assert (f_left == Node z t1 t2); assert (f_right == Node x t3 t4); assert (lright == Node y t2 t3); // Left part assert (is_balanced lright); assert (height t1 - height t2 <= 1); assert (height t2 - height t1 <= 1); assert (is_balanced t1); assert (is_balanced (Node y t2 t3)); assert (is_balanced t2); assert (is_balanced f_left); // Right part assert (height t3 - height t4 <= 1); assert (height t4 - height t3 <= 1); assert (is_balanced t3); assert (is_balanced t4); assert (is_balanced f_right) ) else ( rotate_right_bst cmp x; Classical.move_requires (rotate_right_key_left cmp x) root; Classical.move_requires (rotate_right_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( rotate_right_left_bst cmp x; Classical.move_requires (rotate_right_left_key_left cmp x) root; Classical.move_requires (rotate_right_left_key_right cmp x) root; let Node x t1 (Node z (Node y t2 t3) t4) = x in assert (f_data == y); assert (f_left == Node x t1 t2); assert (f_right == Node z t3 t4); // Right part assert (is_balanced rleft); assert (height t3 - height t4 <= 1); assert (height t4 - height t4 <= 1); assert (is_balanced (Node y t2 t3)); assert (is_balanced f_right); // Left part assert (is_balanced t1); assert (is_balanced t2); assert (is_balanced f_left) ) else ( rotate_left_bst cmp x; Classical.move_requires (rotate_left_key_left cmp x) root; Classical.move_requires (rotate_left_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) ) (** Insertion **)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.tree a -> key: a -> Trees.tree a
Prims.Tot
[ "total" ]
[]
[ "Trees.cmp", "Trees.tree", "Trees.Node", "Trees.Leaf", "Prims.op_GreaterThanOrEqual", "Trees.rebalance_avl", "Trees.insert_avl", "Prims.bool", "Prims.int" ]
[ "recursion" ]
false
false
false
true
false
let rec insert_avl (#a: Type) (cmp: cmp a) (x: tree a) (key: a) : tree a =
match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then (let new_left = insert_avl cmp left key in let tmp = Node data new_left right in rebalance_avl tmp) else (let new_right = insert_avl cmp right key in let tmp = Node data left new_right in rebalance_avl tmp)
false
Trees.fst
Trees.insert_avl_proof
val insert_avl_proof (#a: Type) (cmp: cmp a) (x: avl a cmp) (key: a) : Lemma (requires is_avl cmp x) (ensures is_avl cmp (insert_avl cmp x key))
val insert_avl_proof (#a: Type) (cmp: cmp a) (x: avl a cmp) (key: a) : Lemma (requires is_avl cmp x) (ensures is_avl cmp (insert_avl cmp x key))
let insert_avl_proof (#a: Type) (cmp:cmp a) (x: avl a cmp) (key: a) : Lemma (requires is_avl cmp x) (ensures is_avl cmp (insert_avl cmp x key)) = Classical.forall_intro (Classical.move_requires (insert_avl_proof_aux cmp x key))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 85, "end_line": 549, "start_col": 0, "start_line": 547 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) let rotate_left_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_left_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) (** Balancing operation for AVLs *) let rebalance_avl (#a: Type) (x: tree a) : tree a = match x with | Leaf -> x | Node data left right -> if is_balanced x then x else ( if height left - height right > 1 then ( let Node ldata lleft lright = left in if height lright > height lleft then ( match rotate_left_right x with | Some y -> y | _ -> x ) else ( match rotate_right x with | Some y -> y | _ -> x ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( match rotate_right_left x with | Some y -> y | _ -> x ) else ( match rotate_left x with | Some y -> y | _ -> x ) ) else ( x ) ) let rebalance_avl_proof (#a: Type) (cmp:cmp a) (x: tree a) (root:a) : Lemma (requires is_bst cmp x /\ ( match x with | Leaf -> True | Node data left right -> is_balanced left /\ is_balanced right /\ height left - height right <= 2 /\ height right - height left <= 2 ) ) (ensures is_avl cmp (rebalance_avl x) /\ (forall_keys x (key_left cmp root) ==> forall_keys (rebalance_avl x) (key_left cmp root)) /\ (forall_keys x (key_right cmp root) ==> forall_keys (rebalance_avl x) (key_right cmp root)) ) = match x with | Leaf -> () | Node data left right -> let x_f = rebalance_avl x in let Node f_data f_left f_right = x_f in if is_balanced x then () else ( if height left - height right > 1 then ( assert (height left = height right + 2); let Node ldata lleft lright = left in if height lright > height lleft then ( assert (height left = height lright + 1); rotate_left_right_bst cmp x; Classical.move_requires (rotate_left_right_key_left cmp x) root; Classical.move_requires (rotate_left_right_key_right cmp x) root; let Node y t2 t3 = lright in let Node x (Node z t1 (Node y t2 t3)) t4 = x in assert (f_data == y); assert (f_left == Node z t1 t2); assert (f_right == Node x t3 t4); assert (lright == Node y t2 t3); // Left part assert (is_balanced lright); assert (height t1 - height t2 <= 1); assert (height t2 - height t1 <= 1); assert (is_balanced t1); assert (is_balanced (Node y t2 t3)); assert (is_balanced t2); assert (is_balanced f_left); // Right part assert (height t3 - height t4 <= 1); assert (height t4 - height t3 <= 1); assert (is_balanced t3); assert (is_balanced t4); assert (is_balanced f_right) ) else ( rotate_right_bst cmp x; Classical.move_requires (rotate_right_key_left cmp x) root; Classical.move_requires (rotate_right_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( rotate_right_left_bst cmp x; Classical.move_requires (rotate_right_left_key_left cmp x) root; Classical.move_requires (rotate_right_left_key_right cmp x) root; let Node x t1 (Node z (Node y t2 t3) t4) = x in assert (f_data == y); assert (f_left == Node x t1 t2); assert (f_right == Node z t3 t4); // Right part assert (is_balanced rleft); assert (height t3 - height t4 <= 1); assert (height t4 - height t4 <= 1); assert (is_balanced (Node y t2 t3)); assert (is_balanced f_right); // Left part assert (is_balanced t1); assert (is_balanced t2); assert (is_balanced f_left) ) else ( rotate_left_bst cmp x; Classical.move_requires (rotate_left_key_left cmp x) root; Classical.move_requires (rotate_left_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) ) (** Insertion **) let rec insert_avl (#a: Type) (cmp:cmp a) (x: tree a) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then ( let new_left = insert_avl cmp left key in let tmp = Node data new_left right in rebalance_avl tmp ) else ( let new_right = insert_avl cmp right key in let tmp = Node data left new_right in rebalance_avl tmp ) #push-options "--z3rlimit 50" let rec insert_avl_proof_aux (#a: Type) (cmp:cmp a) (x: avl a cmp) (key: a) (root:a) : Lemma (requires is_avl cmp x) (ensures ( let res = insert_avl cmp x key in is_avl cmp res /\ height x <= height res /\ height res <= height x + 1 /\ (forall_keys x (key_left cmp root) /\ key_left cmp root key ==> forall_keys res (key_left cmp root)) /\ (forall_keys x (key_right cmp root) /\ key_right cmp root key ==> forall_keys res (key_right cmp root))) ) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then ( let new_left = insert_avl cmp left key in let tmp = Node data new_left right in insert_avl_proof_aux cmp left key data; // Need this one for propagating that all elements are smaller than root insert_avl_proof_aux cmp left key root; rebalance_avl_proof cmp tmp root ) else ( let new_right = insert_avl cmp right key in let tmp = Node data left new_right in insert_avl_proof_aux cmp right key data; insert_avl_proof_aux cmp right key root; rebalance_avl_proof cmp tmp root ) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.avl a cmp -> key: a -> FStar.Pervasives.Lemma (requires Trees.is_avl cmp x) (ensures Trees.is_avl cmp (Trees.insert_avl cmp x key))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.avl", "FStar.Classical.forall_intro", "Prims.l_imp", "Trees.is_avl", "Prims.l_and", "Trees.insert_avl", "Prims.b2t", "Prims.op_LessThanOrEqual", "Trees.height", "Prims.op_Addition", "Trees.forall_keys", "Trees.key_left", "Trees.key_right", "FStar.Classical.move_requires", "Trees.insert_avl_proof_aux", "Prims.unit", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let insert_avl_proof (#a: Type) (cmp: cmp a) (x: avl a cmp) (key: a) : Lemma (requires is_avl cmp x) (ensures is_avl cmp (insert_avl cmp x key)) =
Classical.forall_intro (Classical.move_requires (insert_avl_proof_aux cmp x key))
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_encrypt_st
val chacha20_encrypt_st : w: Hacl.Impl.Chacha20.Core32xN.lanes -> Type0
let chacha20_encrypt_st (w:lanes) = len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t{v ctr + w <= max_size_t } -> Stack unit (requires fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_encrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text))
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 115, "end_line": 233, "start_col": 0, "start_line": 221 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame() noextract val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_last #w ctx len out incr text = push_frame(); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame() noextract val chacha20_update: #w:lanes -> ctx:state w -> len:size_t{v len / (w * 64) <= max_size_t} -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ eq_or_disjoint text out /\ disjoint text ctx /\ disjoint out ctx)) (ensures (fun h0 _ h1 -> modifies (loc ctx |+| loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_update (as_seq h0 ctx) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_update #w ctx len out text = assert_norm (range (v len / v (size w *! 64ul)) U32); let blocks = len /. (size w *! 64ul) in let rem = len %. (size w *! 64ul) in let h0 = ST.get() in map_blocks h0 len (size w *! 64ul) text out (fun h -> Spec.chacha20_encrypt_block (as_seq h0 ctx)) (fun h -> Spec.chacha20_encrypt_last (as_seq h0 ctx)) (fun i -> chacha20_encrypt_block ctx (sub out (i *! (size w *! 64ul)) (size w *! 64ul)) i (sub text (i *! (size w *! 64ul)) (size w *! 64ul))) (fun i -> chacha20_encrypt_last ctx rem (sub out (i *! (size w *! 64ul)) rem) i (sub text (i *! (size w *! 64ul)) rem)) noextract val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_vec #w len out text key n ctr = push_frame(); let ctx = create_state w in chacha20_init #w ctx key n ctr; chacha20_update #w ctx len out text; pop_frame()
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w: Hacl.Impl.Chacha20.Core32xN.lanes -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.eq_or_disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.as_seq", "Spec.Chacha20.chacha20_encrypt_bytes" ]
[]
false
false
false
true
true
let chacha20_encrypt_st (w: lanes) =
len: size_t -> out: lbuffer uint8 len -> text: lbuffer uint8 len -> key: lbuffer uint8 32ul -> n: lbuffer uint8 12ul -> ctr: size_t{v ctr + w <= max_size_t} -> Stack unit (requires fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_encrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text))
false
Trees.fst
Trees.rotate_right_key_right
val rotate_right_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root))
val rotate_right_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root))
let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 62, "end_line": 284, "start_col": 0, "start_line": 278 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_right cmp root) /\ Some? (Trees.rotate_right r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_right r)) (Trees.key_right cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.Node", "Trees.key_right", "Prims.unit", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_right", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_right_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) =
match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root))
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_decrypt
val chacha20_decrypt: #w:lanes -> chacha20_decrypt_st w
val chacha20_decrypt: #w:lanes -> chacha20_decrypt_st w
let chacha20_decrypt #w len out cipher key n ctr = let h0 = ST.get () in chacha20_decrypt_vec #w len out cipher key n ctr; Chacha20Equiv.lemma_chacha20_vec_equiv #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher)
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 100, "end_line": 286, "start_col": 0, "start_line": 283 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame() noextract val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_last #w ctx len out incr text = push_frame(); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame() noextract val chacha20_update: #w:lanes -> ctx:state w -> len:size_t{v len / (w * 64) <= max_size_t} -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ eq_or_disjoint text out /\ disjoint text ctx /\ disjoint out ctx)) (ensures (fun h0 _ h1 -> modifies (loc ctx |+| loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_update (as_seq h0 ctx) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_update #w ctx len out text = assert_norm (range (v len / v (size w *! 64ul)) U32); let blocks = len /. (size w *! 64ul) in let rem = len %. (size w *! 64ul) in let h0 = ST.get() in map_blocks h0 len (size w *! 64ul) text out (fun h -> Spec.chacha20_encrypt_block (as_seq h0 ctx)) (fun h -> Spec.chacha20_encrypt_last (as_seq h0 ctx)) (fun i -> chacha20_encrypt_block ctx (sub out (i *! (size w *! 64ul)) (size w *! 64ul)) i (sub text (i *! (size w *! 64ul)) (size w *! 64ul))) (fun i -> chacha20_encrypt_last ctx rem (sub out (i *! (size w *! 64ul)) rem) i (sub text (i *! (size w *! 64ul)) rem)) noextract val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_vec #w len out text key n ctr = push_frame(); let ctx = create_state w in chacha20_init #w ctx key n ctr; chacha20_update #w ctx len out text; pop_frame() inline_for_extraction noextract let chacha20_encrypt_st (w:lanes) = len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t{v ctr + w <= max_size_t } -> Stack unit (requires fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_encrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)) noextract val chacha20_encrypt: #w:lanes -> chacha20_encrypt_st w [@ Meta.Attribute.specialize ] let chacha20_encrypt #w len out text key n ctr = let h0 = ST.get () in chacha20_encrypt_vec #w len out text key n ctr; Chacha20Equiv.lemma_chacha20_vec_equiv #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text) noextract val chacha20_decrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> cipher:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_decrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher))) [@ Meta.Attribute.inline_ ] let chacha20_decrypt_vec #w len out cipher key n ctr = push_frame(); let ctx = create_state w in chacha20_init ctx key n ctr; chacha20_update ctx len out cipher; pop_frame() inline_for_extraction noextract let chacha20_decrypt_st (w:lanes) = len:size_t -> out:lbuffer uint8 len -> cipher:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t{v ctr + w <= max_size_t } -> Stack unit (requires fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_decrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher)) noextract val chacha20_decrypt: #w:lanes -> chacha20_decrypt_st w
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Chacha20.Vec.chacha20_decrypt_st w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Spec.Chacha20.Equiv.lemma_chacha20_vec_equiv", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "Hacl.Impl.Chacha20.Vec.chacha20_decrypt_vec", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
let chacha20_decrypt #w len out cipher key n ctr =
let h0 = ST.get () in chacha20_decrypt_vec #w len out cipher key n ctr; Chacha20Equiv.lemma_chacha20_vec_equiv #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher)
false
Trees.fst
Trees.forall_keys_trans
val forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: (a -> bool)) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2)
val forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: (a -> bool)) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2)
let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 75, "end_line": 190, "start_col": 0, "start_line": 184 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Trees.tree a -> cond1: (_: a -> Prims.bool) -> cond2: (_: a -> Prims.bool) -> FStar.Pervasives.Lemma (requires (forall (x: a). cond1 x ==> cond2 x) /\ Trees.forall_keys t cond1) (ensures Trees.forall_keys t cond2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.tree", "Prims.bool", "Trees.forall_keys_trans", "Prims.unit", "Prims.l_and", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "Trees.forall_keys", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: (a -> bool)) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) =
match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2
false
Trees.fst
Trees.rotate_right_key_left
val rotate_right_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root))
val rotate_right_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root))
let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 276, "start_col": 0, "start_line": 270 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_left cmp root) /\ Some? (Trees.rotate_right r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_right r)) (Trees.key_left cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.Node", "Trees.key_left", "Prims.unit", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_right", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_right_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) =
match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root))
false
Trees.fst
Trees.rotate_left_right_key_left
val rotate_left_right_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root))
val rotate_left_right_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root))
let rotate_left_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 50, "end_line": 323, "start_col": 0, "start_line": 311 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_left cmp root) /\ Some? (Trees.rotate_left_right r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_left_right r)) (Trees.key_left cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.key_left", "Prims.unit", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_left_right", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_left_right_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) =
match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root))
false
Trees.fst
Trees.rotate_right_left_key_left
val rotate_right_left_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root))
val rotate_right_left_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root))
let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 50, "end_line": 296, "start_col": 0, "start_line": 286 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_left cmp root) /\ Some? (Trees.rotate_right_left r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_right_left r)) (Trees.key_left cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.key_left", "Prims.unit", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_right_left", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_right_left_key_left (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) =
match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root))
false
Trees.fst
Trees.rotate_left_key_right
val rotate_left_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root))
val rotate_left_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root))
let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 62, "end_line": 268, "start_col": 0, "start_line": 262 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_right cmp root) /\ Some? (Trees.rotate_left r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_left r)) (Trees.key_right cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.Node", "Trees.key_right", "Prims.unit", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_left", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_left_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) =
match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root))
false
Trees.fst
Trees.rotate_left_right_key_right
val rotate_left_right_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root))
val rotate_left_right_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root))
let rotate_left_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root))
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 337, "start_col": 0, "start_line": 325 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) let rotate_left_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.forall_keys r (Trees.key_right cmp root) /\ Some? (Trees.rotate_left_right r)) (ensures Trees.forall_keys (Some?.v (Trees.rotate_left_right r)) (Trees.key_right cmp root))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Prims._assert", "Prims.b2t", "Trees.forall_keys", "Trees.key_right", "Prims.unit", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_left_right", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_left_right_key_right (#a: Type) (cmp: cmp a) (r: tree a) (root: a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root)) =
match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> assert (forall_keys (Node z t1 (Node y t2 t3)) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root))
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_encrypt
val chacha20_encrypt: #w:lanes -> chacha20_encrypt_st w
val chacha20_encrypt: #w:lanes -> chacha20_encrypt_st w
let chacha20_encrypt #w len out text key n ctr = let h0 = ST.get () in chacha20_encrypt_vec #w len out text key n ctr; Chacha20Equiv.lemma_chacha20_vec_equiv #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 98, "end_line": 241, "start_col": 0, "start_line": 238 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame() noextract val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_last #w ctx len out incr text = push_frame(); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame() noextract val chacha20_update: #w:lanes -> ctx:state w -> len:size_t{v len / (w * 64) <= max_size_t} -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ eq_or_disjoint text out /\ disjoint text ctx /\ disjoint out ctx)) (ensures (fun h0 _ h1 -> modifies (loc ctx |+| loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_update (as_seq h0 ctx) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_update #w ctx len out text = assert_norm (range (v len / v (size w *! 64ul)) U32); let blocks = len /. (size w *! 64ul) in let rem = len %. (size w *! 64ul) in let h0 = ST.get() in map_blocks h0 len (size w *! 64ul) text out (fun h -> Spec.chacha20_encrypt_block (as_seq h0 ctx)) (fun h -> Spec.chacha20_encrypt_last (as_seq h0 ctx)) (fun i -> chacha20_encrypt_block ctx (sub out (i *! (size w *! 64ul)) (size w *! 64ul)) i (sub text (i *! (size w *! 64ul)) (size w *! 64ul))) (fun i -> chacha20_encrypt_last ctx rem (sub out (i *! (size w *! 64ul)) rem) i (sub text (i *! (size w *! 64ul)) rem)) noextract val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_vec #w len out text key n ctr = push_frame(); let ctx = create_state w in chacha20_init #w ctx key n ctr; chacha20_update #w ctx len out text; pop_frame() inline_for_extraction noextract let chacha20_encrypt_st (w:lanes) = len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t{v ctr + w <= max_size_t } -> Stack unit (requires fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_encrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)) noextract val chacha20_encrypt: #w:lanes -> chacha20_encrypt_st w
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Chacha20.Vec.chacha20_encrypt_st w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Spec.Chacha20.Equiv.lemma_chacha20_vec_equiv", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "Hacl.Impl.Chacha20.Vec.chacha20_encrypt_vec", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
let chacha20_encrypt #w len out text key n ctr =
let h0 = ST.get () in chacha20_encrypt_vec #w len out text key n ctr; Chacha20Equiv.lemma_chacha20_vec_equiv #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)
false
Trees.fst
Trees.rotate_right_bst
val rotate_right_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r)))
val rotate_right_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r)))
let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z)
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 62, "end_line": 206, "start_col": 0, "start_line": 200 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> r: Trees.tree a -> FStar.Pervasives.Lemma (requires Trees.is_bst cmp r /\ Some? (Trees.rotate_right r)) (ensures Trees.is_bst cmp (Some?.v (Trees.rotate_right r)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Trees.forall_keys_trans", "Trees.key_right", "Prims.unit", "Prims._assert", "Prims.b2t", "Trees.is_bst", "Trees.Node", "Prims.l_and", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_right", "Prims.squash", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rotate_right_bst (#a: Type) (cmp: cmp a) (r: tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) =
match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z)
false
Trees.fst
Trees.rebalance_avl
val rebalance_avl (#a: Type) (x: tree a) : tree a
val rebalance_avl (#a: Type) (x: tree a) : tree a
let rebalance_avl (#a: Type) (x: tree a) : tree a = match x with | Leaf -> x | Node data left right -> if is_balanced x then x else ( if height left - height right > 1 then ( let Node ldata lleft lright = left in if height lright > height lleft then ( match rotate_left_right x with | Some y -> y | _ -> x ) else ( match rotate_right x with | Some y -> y | _ -> x ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( match rotate_right_left x with | Some y -> y | _ -> x ) else ( match rotate_left x with | Some y -> y | _ -> x ) ) else ( x ) )
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 376, "start_col": 0, "start_line": 342 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) let rotate_left_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_left_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) (** Balancing operation for AVLs *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Trees.tree a -> Trees.tree a
Prims.Tot
[ "total" ]
[]
[ "Trees.tree", "Trees.is_balanced", "Prims.bool", "Prims.op_GreaterThan", "Prims.op_Subtraction", "Trees.height", "Trees.rotate_left_right", "FStar.Pervasives.Native.option", "Trees.rotate_right", "Prims.op_LessThan", "Prims.op_Minus", "Trees.rotate_right_left", "Trees.rotate_left" ]
[]
false
false
false
true
false
let rebalance_avl (#a: Type) (x: tree a) : tree a =
match x with | Leaf -> x | Node data left right -> if is_balanced x then x else (if height left - height right > 1 then (let Node ldata lleft lright = left in if height lright > height lleft then (match rotate_left_right x with | Some y -> y | _ -> x) else (match rotate_right x with | Some y -> y | _ -> x)) else if height left - height right < - 1 then (let Node rdata rleft rright = right in if height rleft > height rright then (match rotate_right_left x with | Some y -> y | _ -> x) else (match rotate_left x with | Some y -> y | _ -> x)) else (x))
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_decrypt_st
val chacha20_decrypt_st : w: Hacl.Impl.Chacha20.Core32xN.lanes -> Type0
let chacha20_decrypt_st (w:lanes) = len:size_t -> out:lbuffer uint8 len -> cipher:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t{v ctr + w <= max_size_t } -> Stack unit (requires fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_decrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher))
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 117, "end_line": 278, "start_col": 0, "start_line": 266 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame() noextract val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_last #w ctx len out incr text = push_frame(); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame() noextract val chacha20_update: #w:lanes -> ctx:state w -> len:size_t{v len / (w * 64) <= max_size_t} -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ eq_or_disjoint text out /\ disjoint text ctx /\ disjoint out ctx)) (ensures (fun h0 _ h1 -> modifies (loc ctx |+| loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_update (as_seq h0 ctx) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_update #w ctx len out text = assert_norm (range (v len / v (size w *! 64ul)) U32); let blocks = len /. (size w *! 64ul) in let rem = len %. (size w *! 64ul) in let h0 = ST.get() in map_blocks h0 len (size w *! 64ul) text out (fun h -> Spec.chacha20_encrypt_block (as_seq h0 ctx)) (fun h -> Spec.chacha20_encrypt_last (as_seq h0 ctx)) (fun i -> chacha20_encrypt_block ctx (sub out (i *! (size w *! 64ul)) (size w *! 64ul)) i (sub text (i *! (size w *! 64ul)) (size w *! 64ul))) (fun i -> chacha20_encrypt_last ctx rem (sub out (i *! (size w *! 64ul)) rem) i (sub text (i *! (size w *! 64ul)) rem)) noextract val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_vec #w len out text key n ctr = push_frame(); let ctx = create_state w in chacha20_init #w ctx key n ctr; chacha20_update #w ctx len out text; pop_frame() inline_for_extraction noextract let chacha20_encrypt_st (w:lanes) = len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t{v ctr + w <= max_size_t } -> Stack unit (requires fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_encrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)) noextract val chacha20_encrypt: #w:lanes -> chacha20_encrypt_st w [@ Meta.Attribute.specialize ] let chacha20_encrypt #w len out text key n ctr = let h0 = ST.get () in chacha20_encrypt_vec #w len out text key n ctr; Chacha20Equiv.lemma_chacha20_vec_equiv #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text) noextract val chacha20_decrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> cipher:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_decrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher))) [@ Meta.Attribute.inline_ ] let chacha20_decrypt_vec #w len out cipher key n ctr = push_frame(); let ctx = create_state w in chacha20_init ctx key n ctr; chacha20_update ctx len out cipher; pop_frame()
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w: Hacl.Impl.Chacha20.Core32xN.lanes -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.eq_or_disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.as_seq", "Spec.Chacha20.chacha20_decrypt_bytes" ]
[]
false
false
false
true
true
let chacha20_decrypt_st (w: lanes) =
len: size_t -> out: lbuffer uint8 len -> cipher: lbuffer uint8 len -> key: lbuffer uint8 32ul -> n: lbuffer uint8 12ul -> ctr: size_t{v ctr + w <= max_size_t} -> Stack unit (requires fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_decrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher))
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_core
val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0)))
val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0)))
let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 61, "start_col": 0, "start_line": 54 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0)))
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Hacl.Impl.Chacha20.Core32xN.state w -> ctx0: Hacl.Impl.Chacha20.Core32xN.state w -> ctr: Lib.IntTypes.size_t{w * Lib.IntTypes.v ctr <= Lib.IntTypes.max_size_t} -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Hacl.Impl.Chacha20.Core32xN.state", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Lib.Buffer.op_Array_Assignment", "Hacl.Impl.Chacha20.Core32xN.uint32xN", "FStar.UInt32.__uint_to_t", "Prims.unit", "Lib.IntVector.op_Plus_Bar", "Lib.IntVector.vec_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Hacl.Impl.Chacha20.Core32xN.sum_state", "Hacl.Impl.Chacha20.Vec.rounds", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntVector.vec_v", "Lib.Sequence.create", "Lib.IntVector.vec_load", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u32", "Lib.IntTypes.size_to_uint32", "Hacl.Impl.Chacha20.Core32xN.copy_state" ]
[]
false
true
false
false
false
let chacha20_core #w k ctx ctr =
copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv
false
Retype.fst
Retype.assumption'
val assumption': Prims.unit -> Tac unit
val assumption': Prims.unit -> Tac unit
let assumption' () : Tac unit = apply_raw (`FStar.Squash.return_squash); assumption ()
{ "file_name": "examples/native_tactics/Retype.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 31, "start_col": 0, "start_line": 29 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Retype // Changing the type of a binder open FStar.Tactics.V2 assume val p : prop assume val q : prop assume val r : prop assume val l : unit -> Lemma (p == r) assume val l2 : unit -> Lemma (requires r) (ensures q)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Order.fst.checked" ], "interface_file": false, "source_file": "Retype.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.assumption", "FStar.Tactics.V2.Derived.apply_raw" ]
[]
false
true
false
false
false
let assumption' () : Tac unit =
apply_raw (`FStar.Squash.return_squash); assumption ()
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.setup1
val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0)))
val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0)))
let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n)
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 101, "start_col": 0, "start_line": 86 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ctx: Lib.Buffer.lbuffer Lib.IntTypes.uint32 16ul -> k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul -> ctr0: Lib.IntTypes.size_t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint32", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.uint8", "Lib.IntTypes.size_t", "Lib.Buffer.update_sub_f", "FStar.Monotonic.HyperStack.mem", "Lib.ByteSequence.uints_from_bytes_le", "Lib.IntTypes.U32", "Lib.IntTypes.SEC", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.Sequence.lseq", "Prims.unit", "Lib.ByteBuffer.uints_from_bytes_le", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "FStar.UInt32.uint_to_t", "Lib.Buffer.sub", "FStar.HyperStack.ST.get", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.size_to_uint32", "Lib.Sequence.map", "Lib.IntTypes.secret", "Hacl.Spec.Chacha20.Vec.chacha20_constants", "Lib.Buffer.mapT", "Lib.Buffer.CONST", "Hacl.Impl.Chacha20.Vec.chacha20_constants", "FStar.UInt32.t", "Lib.Buffer.recall_contents" ]
[]
false
true
false
false
false
let setup1 ctx k n ctr =
let h0 = ST.get () in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get () in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get () in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get () in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n)
false
TwoLockQueue.fst
TwoLockQueue.maybe_ghost_pts_to
val maybe_ghost_pts_to : x: Steel.Reference.ghost_ref (Queue.Def.t a) -> hd: Queue.Def.t a -> o: FStar.Pervasives.Native.option (Queue.Def.t a) -> Steel.Effect.Common.vprop
let maybe_ghost_pts_to #a (x:ghost_ref (Q.t a)) ([@@@ smt_fallback] hd:Q.t a) (o:option (Q.t a)) = match o with | None -> ghost_pts_to x half hd | Some next -> ghost_pts_to x half next `star` (h_exists (pts_to hd full_perm))
{ "file_name": "share/steel/examples/steel/TwoLockQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 81, "end_line": 212, "start_col": 0, "start_line": 209 }
module TwoLockQueue open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock module L = FStar.List.Tot module U = Steel.Utils module Q = Queue /// This module provides an implementation of Michael and Scott's two lock queue, using the /// abstract interface for queues provided in Queue.fsti. /// This implementation allows an enqueue and a dequeue operation to safely operate in parallel. /// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation, /// ensuring that at most one enqueue (resp. dequeue) is happening at any time /// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue #push-options "--ide_id_info_off" /// Adding the definition of the vprop equivalence to the context, for proof purposes let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) = Classical.forall_intro_2 reveal_equiv (* Some wrappers to reduce clutter in the code *) [@@__reduce__] let full = full_perm [@@__reduce__] let half = half_perm full (* Wrappers around fst and snd to avoid overnormalization. TODO: The frame inference tactic should not normalize fst and snd *) let fst x = fst x let snd x = snd x (* Some wrappers around Steel functions which are easier to use inside this module *) let ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1}) (x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r p x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1) = let _ = ghost_gather_pt #a #u #p0 #p1 r in () let rewrite #u (p q:vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) = rewrite_slprop p q (fun _ -> reveal_equiv p q) let elim_pure (#p:prop) #u () : SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) = let _ = Steel.Effect.Atomic.elim_pure p in () let open_exists (#a:Type) (#opened_invariants:_) (#p:a -> vprop) (_:unit) : SteelGhostT (Ghost.erased a) opened_invariants (h_exists p) (fun r -> p (reveal r)) = let v : erased a = witness_exists () in v (*** Queue invariant ***) /// The invariant associated to the lock. Basically a variant of the /// Owicki-Gries invariant, but applied to queues [@@__reduce__] let lock_inv #a (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) = h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) let intro_lock_inv #a #u (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (fun _ -> lock_inv ptr ghost) = assert_spinoff (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) == lock_inv ptr ghost); rewrite_slprop (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (lock_inv _ _) (fun _ -> ()) /// The type of a queue pointer. /// Contains the concrete pointer [ptr], the pointer to ghost state [ghost], /// and a lock [lock] protecting the invariant relating the concrete and ghost states noeq type q_ptr (a:Type) = { ptr : ref (Q.t a); ghost: ghost_ref (Q.t a); lock: lock (lock_inv ptr ghost); } /// The global queue invariant, which will be shared by the enqueuer and the dequeuer. /// Again, inspired by the Owicki-Gries counter: It contains half the permission for the ghost /// state of the enqueuer and dequeuer, while ensuring that the concrete queue always remains /// a valid queue let queue_invariant (#a:_) ([@@@smt_fallback]head:q_ptr a) ([@@@smt_fallback] tail:q_ptr a) = h_exists (fun (h:Q.t a) -> h_exists (fun (t:Q.t a) -> ghost_pts_to head.ghost half h `star` ghost_pts_to tail.ghost half t `star` Q.queue h t)) let pack_queue_invariant (#a:_) (#u:_) (x:erased (Q.t a)) (y:erased (Q.t a)) (head tail:q_ptr a) : SteelGhostT unit u (ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y) (fun _ -> queue_invariant head tail) = intro_exists (reveal y) (fun y -> ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y); intro_exists (reveal x) (fun x -> h_exists (fun y -> ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y)) /// The type of a queue. It contains a head and tail pointers, each with their own ghost state, /// as well as the global queue invariant [inv]. Note that compared to the locks in the head and tail /// pointers with type `q_ptr`, since invariant is a true Steel invariant, only accessible inside /// atomic computations noeq type t (a:Type0) = { head : q_ptr a; tail : q_ptr a; inv : inv (queue_invariant head tail) } /// Creating a new queue. let new_queue (#a:_) (x:a) : SteelT (t a) emp (fun _ -> emp) = let new_qptr (#a:_) (q:Q.t a) : SteelT (q_ptr a) emp (fun qp -> ghost_pts_to qp.ghost half q) = // Allocates the concrete pointer. let ptr = alloc_pt q in // Allocates the ghost state, and sets the corresponding lock invariant let ghost = ghost_alloc_pt q in ghost_share_pt ghost; intro_exists _ (fun q -> pts_to ptr full q `star` ghost_pts_to ghost half q); let lock = Steel.SpinLock.new_lock _ in { ptr; ghost; lock} in // Creating a concrete queue let hd = Q.new_queue x in // Creating the head and queue pointers let head = new_qptr hd in let tail = new_qptr hd in // Creating the global queue invariant pack_queue_invariant (hide hd) (hide hd) head tail; let inv = new_invariant _ in // Packing the different components to return a queue, as defined in type `t` return ({ head; tail; inv }) #restart-solver /// Enqueues element [x] in the queue [hdl] let enqueue (#a:_) (hdl:t a) (x:a) : SteelT unit emp (fun _ -> emp) = // Blocks until it can acquire the tail lock corresponding to the enqueuer Steel.SpinLock.acquire hdl.tail.lock; let cell = Q.({ data = x; next = null} ) in let v:erased (Q.t a) = open_exists () in let tl = read_pt hdl.tail.ptr in // Creates a new cell for the enqueued element let node = alloc_pt cell in // Core, atomic enqueue function, calling the concrete enqueue function while also // modifying ghost state to preserve the invariants let enqueue_core #u () : SteelAtomicT unit u (queue_invariant hdl.head hdl.tail `star` (ghost_pts_to hdl.tail.ghost half tl `star` pts_to node full cell)) (fun _ -> queue_invariant hdl.head hdl.tail `star` ghost_pts_to hdl.tail.ghost half node) = let open FStar.Ghost in let h = open_exists () in let t = open_exists () in ghost_gather tl hdl.tail.ghost; Q.enqueue tl node; ghost_write_pt hdl.tail.ghost node; ghost_share_pt #_ #_ hdl.tail.ghost; pack_queue_invariant h (hide node) hdl.head hdl.tail; return () in // Actually executing the atomic enqueue operation while preserving the global queue invariant let r1 = with_invariant hdl.inv enqueue_core in // Updates the queue tail pointer let r2 = write_pt hdl.tail.ptr node in // Updates the queue tail ghost state let r3 = intro_exists _ (fun (n:(Q.t a)) -> pts_to hdl.tail.ptr full_perm n `star` ghost_pts_to hdl.tail.ghost half n) in // Releases the tail lock corresponding to the enqueuer Steel.SpinLock.release hdl.tail.lock
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Queue.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "TwoLockQueue.fst" }
[ { "abbrev": true, "full_module": "Queue", "short_module": "Q" }, { "abbrev": true, "full_module": "Steel.Utils", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Steel.Reference.ghost_ref (Queue.Def.t a) -> hd: Queue.Def.t a -> o: FStar.Pervasives.Native.option (Queue.Def.t a) -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.Reference.ghost_ref", "Queue.Def.t", "FStar.Pervasives.Native.option", "Steel.Reference.ghost_pts_to", "TwoLockQueue.half", "Steel.Effect.Common.star", "Steel.Effect.Atomic.h_exists", "Queue.Def.cell", "Steel.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Effect.Common.vprop" ]
[]
false
false
false
true
false
let maybe_ghost_pts_to #a (x: ghost_ref (Q.t a)) ([@@@ smt_fallback]hd: Q.t a) (o: option (Q.t a)) =
match o with | None -> ghost_pts_to x half hd | Some next -> (ghost_pts_to x half next) `star` (h_exists (pts_to hd full_perm))
false
Retype.fst
Retype.tau
val tau: Prims.unit -> Tac unit
val tau: Prims.unit -> Tac unit
let tau () : Tac unit = let _ = implies_intro () in let _ = implies_intro () in let _ = implies_intro () in let b = implies_intro () in var_retype b; // call retype, get a goal `p == ?u` let pp = `p in let rr = `r in grewrite pp rr; // rewrite p to q, get `q == ?u` trefl (); // unify apply_lemma (`l); //prove (p == q), asked by grewrite let e = cur_env () in match vars_of_env e with | [_;_;_;b] -> let t = type_of_binding b in let t = norm_term [] t in // contains uvar redexes. if FStar.Order.ne (compare_term t rr) then fail "binder was not retyped?" else (); apply_lemma (`l2); assumption' (); qed () | _ -> fail "should be impossible"
{ "file_name": "examples/native_tactics/Retype.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 61, "start_col": 0, "start_line": 34 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Retype // Changing the type of a binder open FStar.Tactics.V2 assume val p : prop assume val q : prop assume val r : prop assume val l : unit -> Lemma (p == r) assume val l2 : unit -> Lemma (requires r) (ensures q) let assumption' () : Tac unit = apply_raw (`FStar.Squash.return_squash); assumption ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Order.fst.checked" ], "interface_file": false, "source_file": "Retype.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Reflection.V2.Builtins.vars_of_env", "FStar.Stubs.Reflection.V2.Data.binding", "FStar.Tactics.V2.Derived.qed", "Retype.assumption'", "FStar.Tactics.V2.Derived.apply_lemma", "FStar.Order.ne", "FStar.Reflection.V2.Compare.compare_term", "FStar.Tactics.V2.Derived.fail", "Prims.bool", "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.norm_term", "Prims.Nil", "FStar.Pervasives.norm_step", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.V2.Derived.type_of_binding", "Prims.list", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V2.Derived.cur_env", "FStar.Tactics.V2.Derived.trefl", "FStar.Tactics.V2.Derived.grewrite", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V2.Builtins.var_retype", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Logic.implies_intro" ]
[]
false
true
false
false
false
let tau () : Tac unit =
let _ = implies_intro () in let _ = implies_intro () in let _ = implies_intro () in let b = implies_intro () in var_retype b; let pp = `p in let rr = `r in grewrite pp rr; trefl (); apply_lemma (`l); let e = cur_env () in match vars_of_env e with | [_ ; _ ; _ ; b] -> let t = type_of_binding b in let t = norm_term [] t in if FStar.Order.ne (compare_term t rr) then fail "binder was not retyped?"; apply_lemma (`l2); assumption' (); qed () | _ -> fail "should be impossible"
false
Vale.Curve25519.Fast_lemmas_external.fst
Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds
val lemma_prod_bounds (dst_hi dst_lo x y:nat64) : Lemma (requires pow2_64 * dst_hi + dst_lo == x * y) (ensures dst_hi < pow2_64 - 1 /\ (dst_hi < pow2_64 - 2 \/ dst_lo <= 1) )
val lemma_prod_bounds (dst_hi dst_lo x y:nat64) : Lemma (requires pow2_64 * dst_hi + dst_lo == x * y) (ensures dst_hi < pow2_64 - 1 /\ (dst_hi < pow2_64 - 2 \/ dst_lo <= 1) )
let lemma_prod_bounds (dst_hi dst_lo x y:nat64) : Lemma (requires pow2_64 * dst_hi + dst_lo == x * y) (ensures dst_hi < pow2_64 - 1 /\ (dst_hi < pow2_64 - 2 \/ dst_lo <= 1) ) = let result = x * y in FStar.Math.Lemmas.lemma_div_mod result pow2_64; //assert (result = pow2_64 * (result / pow2_64) + result % pow2_64); //assert (result % pow2_64 == dst_lo); //assert (result / pow2_64 == dst_hi); lemma_mul_bound64 x y; ()
{ "file_name": "vale/code/crypto/ecc/curve25519/Vale.Curve25519.Fast_lemmas_external.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 30, "start_col": 0, "start_line": 18 }
module Vale.Curve25519.Fast_lemmas_external open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Mul open Vale.Curve25519.Fast_lemmas_internal let lemma_overflow (dst_hi dst_lo addend:nat64) (old_overflow:bit) : Lemma (requires dst_hi < pow2_64 - 1 /\ (dst_hi < pow2_64 - 2 \/ dst_lo <= 1) /\ addend < pow2_64 - 1 /\ (old_overflow = 0 \/ addend < pow2_64 - 2)) (ensures dst_hi < pow2_64 - 2 \/ dst_lo + addend + old_overflow < pow2_64) = ()
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Curve25519.Fast_lemmas_internal.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.Curve25519.Fast_lemmas_external.fst" }
[ { "abbrev": false, "full_module": "Vale.Curve25519.Fast_lemmas_internal", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519.Fast_defs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dst_hi: Vale.Def.Types_s.nat64 -> dst_lo: Vale.Def.Types_s.nat64 -> x: Vale.Def.Types_s.nat64 -> y: Vale.Def.Types_s.nat64 -> FStar.Pervasives.Lemma (requires Vale.Def.Words_s.pow2_64 * dst_hi + dst_lo == x * y) (ensures dst_hi < Vale.Def.Words_s.pow2_64 - 1 /\ (dst_hi < Vale.Def.Words_s.pow2_64 - 2 \/ dst_lo <= 1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat64", "Prims.unit", "Vale.Curve25519.Fast_lemmas_internal.lemma_mul_bound64", "FStar.Math.Lemmas.lemma_div_mod", "Vale.Def.Words_s.pow2_64", "Prims.int", "FStar.Mul.op_Star", "Prims.eq2", "Prims.op_Addition", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Subtraction", "Prims.l_or", "Prims.op_LessThanOrEqual", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_prod_bounds (dst_hi dst_lo x y: nat64) : Lemma (requires pow2_64 * dst_hi + dst_lo == x * y) (ensures dst_hi < pow2_64 - 1 /\ (dst_hi < pow2_64 - 2 \/ dst_lo <= 1)) =
let result = x * y in FStar.Math.Lemmas.lemma_div_mod result pow2_64; lemma_mul_bound64 x y; ()
false
Trees.fst
Trees.rebalance_avl_proof
val rebalance_avl_proof (#a: Type) (cmp: cmp a) (x: tree a) (root: a) : Lemma (requires is_bst cmp x /\ (match x with | Leaf -> True | Node data left right -> is_balanced left /\ is_balanced right /\ height left - height right <= 2 /\ height right - height left <= 2)) (ensures is_avl cmp (rebalance_avl x) /\ (forall_keys x (key_left cmp root) ==> forall_keys (rebalance_avl x) (key_left cmp root)) /\ (forall_keys x (key_right cmp root) ==> forall_keys (rebalance_avl x) (key_right cmp root)))
val rebalance_avl_proof (#a: Type) (cmp: cmp a) (x: tree a) (root: a) : Lemma (requires is_bst cmp x /\ (match x with | Leaf -> True | Node data left right -> is_balanced left /\ is_balanced right /\ height left - height right <= 2 /\ height right - height left <= 2)) (ensures is_avl cmp (rebalance_avl x) /\ (forall_keys x (key_left cmp root) ==> forall_keys (rebalance_avl x) (key_left cmp root)) /\ (forall_keys x (key_right cmp root) ==> forall_keys (rebalance_avl x) (key_right cmp root)))
let rebalance_avl_proof (#a: Type) (cmp:cmp a) (x: tree a) (root:a) : Lemma (requires is_bst cmp x /\ ( match x with | Leaf -> True | Node data left right -> is_balanced left /\ is_balanced right /\ height left - height right <= 2 /\ height right - height left <= 2 ) ) (ensures is_avl cmp (rebalance_avl x) /\ (forall_keys x (key_left cmp root) ==> forall_keys (rebalance_avl x) (key_left cmp root)) /\ (forall_keys x (key_right cmp root) ==> forall_keys (rebalance_avl x) (key_right cmp root)) ) = match x with | Leaf -> () | Node data left right -> let x_f = rebalance_avl x in let Node f_data f_left f_right = x_f in if is_balanced x then () else ( if height left - height right > 1 then ( assert (height left = height right + 2); let Node ldata lleft lright = left in if height lright > height lleft then ( assert (height left = height lright + 1); rotate_left_right_bst cmp x; Classical.move_requires (rotate_left_right_key_left cmp x) root; Classical.move_requires (rotate_left_right_key_right cmp x) root; let Node y t2 t3 = lright in let Node x (Node z t1 (Node y t2 t3)) t4 = x in assert (f_data == y); assert (f_left == Node z t1 t2); assert (f_right == Node x t3 t4); assert (lright == Node y t2 t3); // Left part assert (is_balanced lright); assert (height t1 - height t2 <= 1); assert (height t2 - height t1 <= 1); assert (is_balanced t1); assert (is_balanced (Node y t2 t3)); assert (is_balanced t2); assert (is_balanced f_left); // Right part assert (height t3 - height t4 <= 1); assert (height t4 - height t3 <= 1); assert (is_balanced t3); assert (is_balanced t4); assert (is_balanced f_right) ) else ( rotate_right_bst cmp x; Classical.move_requires (rotate_right_key_left cmp x) root; Classical.move_requires (rotate_right_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( rotate_right_left_bst cmp x; Classical.move_requires (rotate_right_left_key_left cmp x) root; Classical.move_requires (rotate_right_left_key_right cmp x) root; let Node x t1 (Node z (Node y t2 t3) t4) = x in assert (f_data == y); assert (f_left == Node x t1 t2); assert (f_right == Node z t3 t4); // Right part assert (is_balanced rleft); assert (height t3 - height t4 <= 1); assert (height t4 - height t4 <= 1); assert (is_balanced (Node y t2 t3)); assert (is_balanced f_right); // Left part assert (is_balanced t1); assert (is_balanced t2); assert (is_balanced f_left) ) else ( rotate_left_bst cmp x; Classical.move_requires (rotate_left_key_left cmp x) root; Classical.move_requires (rotate_left_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) )
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 487, "start_col": 0, "start_line": 379 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) let rotate_left_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_left_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) (** Balancing operation for AVLs *) let rebalance_avl (#a: Type) (x: tree a) : tree a = match x with | Leaf -> x | Node data left right -> if is_balanced x then x else ( if height left - height right > 1 then ( let Node ldata lleft lright = left in if height lright > height lleft then ( match rotate_left_right x with | Some y -> y | _ -> x ) else ( match rotate_right x with | Some y -> y | _ -> x ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( match rotate_right_left x with | Some y -> y | _ -> x ) else ( match rotate_left x with | Some y -> y | _ -> x ) ) else ( x ) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.tree a -> root: a -> FStar.Pervasives.Lemma (requires Trees.is_bst cmp x /\ (match x with | Trees.Leaf #_ -> Prims.l_True | Trees.Node #_ _ left right -> Trees.is_balanced left /\ Trees.is_balanced right /\ Trees.height left - Trees.height right <= 2 /\ Trees.height right - Trees.height left <= 2)) (ensures Trees.is_avl cmp (Trees.rebalance_avl x) /\ (Trees.forall_keys x (Trees.key_left cmp root) ==> Trees.forall_keys (Trees.rebalance_avl x) (Trees.key_left cmp root)) /\ (Trees.forall_keys x (Trees.key_right cmp root) ==> Trees.forall_keys (Trees.rebalance_avl x) (Trees.key_right cmp root)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.tree", "Trees.is_balanced", "Prims.bool", "Prims.op_GreaterThan", "Prims.op_Subtraction", "Trees.height", "Prims._assert", "Prims.b2t", "Prims.unit", "Prims.op_LessThanOrEqual", "Trees.Node", "Prims.eq2", "FStar.Classical.move_requires", "Prims.l_and", "Trees.forall_keys", "Trees.key_right", "FStar.Pervasives.Native.uu___is_Some", "Trees.rotate_left_right", "FStar.Pervasives.Native.__proj__Some__item__v", "Trees.rotate_left_right_key_right", "Trees.key_left", "Trees.rotate_left_right_key_left", "Trees.rotate_left_right_bst", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "Trees.rotate_right", "Trees.rotate_right_key_right", "Trees.rotate_right_key_left", "Trees.rotate_right_bst", "Prims.op_LessThan", "Prims.op_Minus", "Trees.rotate_right_left", "Trees.rotate_right_left_key_right", "Trees.rotate_right_left_key_left", "Trees.rotate_right_left_bst", "Trees.rotate_left", "Trees.rotate_left_key_right", "Trees.rotate_left_key_left", "Trees.rotate_left_bst", "Trees.rebalance_avl", "Trees.is_bst", "Prims.l_True", "Prims.logical", "Prims.squash", "Trees.is_avl", "Prims.l_imp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let rebalance_avl_proof (#a: Type) (cmp: cmp a) (x: tree a) (root: a) : Lemma (requires is_bst cmp x /\ (match x with | Leaf -> True | Node data left right -> is_balanced left /\ is_balanced right /\ height left - height right <= 2 /\ height right - height left <= 2)) (ensures is_avl cmp (rebalance_avl x) /\ (forall_keys x (key_left cmp root) ==> forall_keys (rebalance_avl x) (key_left cmp root)) /\ (forall_keys x (key_right cmp root) ==> forall_keys (rebalance_avl x) (key_right cmp root))) =
match x with | Leaf -> () | Node data left right -> let x_f = rebalance_avl x in let Node f_data f_left f_right = x_f in if is_balanced x then () else (if height left - height right > 1 then (assert (height left = height right + 2); let Node ldata lleft lright = left in if height lright > height lleft then (assert (height left = height lright + 1); rotate_left_right_bst cmp x; Classical.move_requires (rotate_left_right_key_left cmp x) root; Classical.move_requires (rotate_left_right_key_right cmp x) root; let Node y t2 t3 = lright in let Node x (Node z t1 (Node y t2 t3)) t4 = x in assert (f_data == y); assert (f_left == Node z t1 t2); assert (f_right == Node x t3 t4); assert (lright == Node y t2 t3); assert (is_balanced lright); assert (height t1 - height t2 <= 1); assert (height t2 - height t1 <= 1); assert (is_balanced t1); assert (is_balanced (Node y t2 t3)); assert (is_balanced t2); assert (is_balanced f_left); assert (height t3 - height t4 <= 1); assert (height t4 - height t3 <= 1); assert (is_balanced t3); assert (is_balanced t4); assert (is_balanced f_right)) else (rotate_right_bst cmp x; Classical.move_requires (rotate_right_key_left cmp x) root; Classical.move_requires (rotate_right_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f))) else if height left - height right < - 1 then (let Node rdata rleft rright = right in if height rleft > height rright then (rotate_right_left_bst cmp x; Classical.move_requires (rotate_right_left_key_left cmp x) root; Classical.move_requires (rotate_right_left_key_right cmp x) root; let Node x t1 (Node z (Node y t2 t3) t4) = x in assert (f_data == y); assert (f_left == Node x t1 t2); assert (f_right == Node z t3 t4); assert (is_balanced rleft); assert (height t3 - height t4 <= 1); assert (height t4 - height t4 <= 1); assert (is_balanced (Node y t2 t3)); assert (is_balanced f_right); assert (is_balanced t1); assert (is_balanced t2); assert (is_balanced f_left)) else (rotate_left_bst cmp x; Classical.move_requires (rotate_left_key_left cmp x) root; Classical.move_requires (rotate_left_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f))))
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.rounds
val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st)))
val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st)))
let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 41, "start_col": 0, "start_line": 31 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st)))
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Hacl.Impl.Chacha20.Core32xN.state w -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Hacl.Impl.Chacha20.Core32xN.state", "Hacl.Impl.Chacha20.Core32xN.double_round", "Prims.unit" ]
[]
false
true
false
false
false
let rounds #w st =
double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.add_frame_well_typed
val add_frame_well_typed (#g: env) (#c: comp_st) (ct: comp_typing_u g c) (#f: term) (ft: tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f)
val add_frame_well_typed (#g: env) (#c: comp_st) (ct: comp_typing_u g c) (#f: term) (ft: tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f)
let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 55, "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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
ct: Pulse.Typing.comp_typing_u g c -> ft: Pulse.Typing.tot_typing g f Pulse.Syntax.Base.tm_vprop -> Pulse.Typing.comp_typing_u g (Pulse.Typing.add_frame c f)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.comp_typing_u", "Pulse.Syntax.Base.term", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.tm_vprop", "Pulse.Typing.Metatheory.Base.admit_comp_typing", "Pulse.Typing.add_frame" ]
[]
false
false
false
false
false
let add_frame_well_typed (#g: env) (#c: comp_st) (ct: comp_typing_u g c) (#f: term) (ft: tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) =
admit_comp_typing _ _
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.st_typing_correctness
val st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c) : comp_typing_u g c
val st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c) : comp_typing_u g c
let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 50, "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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
d: Pulse.Typing.st_typing g t c -> Pulse.Typing.comp_typing_u g c
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.st_typing", "Pulse.Typing.Metatheory.Base.admit_comp_typing", "Pulse.Typing.comp_typing_u" ]
[]
false
false
false
false
false
let st_typing_correctness (#g: env) (#t: st_term) (#c: comp_st) (_: st_typing g t c) : comp_typing_u g c =
admit_comp_typing g c
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.emp_inames_typing
val emp_inames_typing (g: env) : tot_typing g tm_emp_inames tm_inames
val emp_inames_typing (g: env) : tot_typing g tm_emp_inames tm_inames
let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic()
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 81, "end_line": 57, "start_col": 0, "start_line": 57 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> Pulse.Typing.tot_typing g Pulse.Syntax.Base.tm_emp_inames Pulse.Syntax.Base.tm_inames
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.RuntimeUtils.magic", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.tm_emp_inames", "Pulse.Syntax.Base.tm_inames" ]
[]
false
false
false
false
false
let emp_inames_typing (g: env) : tot_typing g tm_emp_inames tm_inames =
RU.magic ()
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.st_typing_correctness_ctot
val st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u)
val st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u)
let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |)
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 45, "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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
_: Pulse.Typing.st_typing g t c -> Prims.dtuple2 (FStar.Ghost.erased Pulse.Syntax.Base.universe) (fun u40 -> Pulse.Typing.universe_of g (Pulse.Syntax.Base.comp_res c) (FStar.Ghost.reveal u40) )
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Prims.b2t", "Pulse.Syntax.Base.uu___is_C_Tot", "Pulse.Typing.st_typing", "Prims.Mkdtuple2", "FStar.Ghost.erased", "Pulse.Syntax.Base.universe", "Pulse.Typing.universe_of", "Pulse.Syntax.Base.comp_res", "FStar.Ghost.reveal", "Pulse.RuntimeUtils.magic", "Prims.dtuple2" ]
[]
false
false
false
false
false
let st_typing_correctness_ctot (#g: env) (#t: st_term) (#c: comp{C_Tot? c}) (_: st_typing g t c) : (u: Ghost.erased universe & universe_of g (comp_res c) u) =
let u:Ghost.erased universe = RU.magic () in let ty:universe_of g (comp_res c) u = RU.magic () in (| u, ty |)
false
Spec.Hash.Lemmas.fst
Spec.Hash.Lemmas.update_multi_associative_blake
val update_multi_associative_blake (a: blake_alg) (h: words_state a) (prevlen1: nat) (prevlen2: nat) (input1: bytes) (input2: bytes): Lemma (requires ( prevlen1 % block_length a = 0 /\ S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length input1 /\ update_multi_pre a prevlen1 (S.append input1 input2))) (ensures ( let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi_pre a prevlen1 input1 /\ update_multi_pre a prevlen2 input2 /\ update_multi a (update_multi a h prevlen1 input1) prevlen2 input2 == update_multi a h prevlen1 input))
val update_multi_associative_blake (a: blake_alg) (h: words_state a) (prevlen1: nat) (prevlen2: nat) (input1: bytes) (input2: bytes): Lemma (requires ( prevlen1 % block_length a = 0 /\ S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length input1 /\ update_multi_pre a prevlen1 (S.append input1 input2))) (ensures ( let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi_pre a prevlen1 input1 /\ update_multi_pre a prevlen2 input2 /\ update_multi a (update_multi a h prevlen1 input1) prevlen2 input2 == update_multi a h prevlen1 input))
let update_multi_associative_blake (a: blake_alg) (h: words_state a) (prevlen1: nat) (prevlen2: nat) (input1: bytes) (input2: bytes): Lemma (requires ( prevlen1 % block_length a == 0 /\ S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length input1 /\ update_multi_pre a prevlen1 (S.append input1 input2))) (ensures ( let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi_pre a prevlen1 input1 /\ update_multi_pre a prevlen2 input2 /\ update_multi a (update_multi a h prevlen1 input1) prevlen2 input2 == update_multi a h prevlen1 input)) = let input = S.append input1 input2 in let nb1 = S.length input1 / block_length a in let nb2 = S.length input2 / block_length a in let nb = S.length input / block_length a in let a' = to_blake_alg a in let f = Spec.Blake2.blake2_update1 a' prevlen1 input in let f1 = Spec.Blake2.blake2_update1 a' prevlen1 input1 in let f2 = Spec.Blake2.blake2_update1 a' prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:words_state a) : Lemma (f i acc == f1 i acc) = lemma_blocki_aux1 a input1 input2 i in let open FStar.Mul in let aux2 (i:nat{i < nb2}) (acc:words_state a) : Lemma (f (i + nb1) acc == f2 i acc) = lemma_update_aux2 a input1 input2 nb1 nb2 prevlen1 prevlen2 i acc in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in let fix = fixed_a (words_state a) in calc (==) { update_multi a h prevlen1 input; (==) { } repeati #(words_state a) nb f h; (==) { repeati_def nb f h } repeat_right 0 nb fix f h; (==) { repeat_right_plus 0 nb1 nb fix f h; repeati_def nb1 f h } repeat_right nb1 nb fix f (repeati nb1 f h); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f f1 h } repeat_right nb1 nb fix f (update_multi a h prevlen1 input1); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 fix fix f2 f (update_multi a h prevlen1 input1) } repeat_right 0 nb2 fix f2 (update_multi a h prevlen1 input1); (==) { repeati_def nb2 f2 (update_multi a h prevlen1 input1) } update_multi a (update_multi a h prevlen1 input1) prevlen2 input2; }
{ "file_name": "specs/lemmas/Spec.Hash.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 204, "start_col": 0, "start_line": 153 }
module Spec.Hash.Lemmas module S = FStar.Seq open Lib.IntTypes open Spec.Agile.Hash open Spec.Hash.Definitions friend Spec.Agile.Hash (** Lemmas about the behavior of update_multi / update_last *) #push-options "--fuel 0 --ifuel 1 --z3rlimit 50" let update_multi_zero a h = match a with | MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h | SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> let rateInBytes = rate a / 8 in let f = Spec.SHA3.absorb_inner rateInBytes in Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h; let nb = 0 / rateInBytes in Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h let update_multi_zero_blake a prevlen h = Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h #pop-options #push-options "--fuel 1" let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma (ensures (update_multi a h () input) == (update a h input)) = let h1 = update_multi a h () input in assert(h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input); if S.length input = 0 then begin assert(h1 == h) end else begin let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in let h2 = update a h block in assert(rem `Seq.equal` Seq.empty); assert(block `Seq.equal` input); let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in assert(h1 == h3) end #pop-options let update_multi_associative (a: hash_alg{not (is_blake a)}) (h: words_state a) (input1: bytes) (input2: bytes): Lemma (requires S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0) (ensures ( let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi a (update_multi a h () input1) () input2 == update_multi a h () input)) = match a with | MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> Lib.UpdateMulti.update_multi_associative (block_length a) (Spec.Agile.Hash.update a) h input1 input2 | SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> let rateInBytes = rate a /8 in let f = Spec.SHA3.absorb_inner rateInBytes in let input = input1 `S.append` input2 in assert (input1 `S.equal` S.slice input 0 (S.length input1)); assert (input2 `S.equal` S.slice input (S.length input1) (S.length input)); Lib.Sequence.Lemmas.repeat_blocks_multi_split (block_length a) (S.length input1) input f h let lemma_blocki_aux1 (a:blake_alg) (s1 s2:bytes) (i:nat{i < S.length s1 / block_length a}) : Lemma (Spec.Blake2.get_blocki (to_blake_alg a) s1 i == Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i) = assert (Spec.Blake2.get_blocki (to_blake_alg a) s1 i `S.equal` Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i) #push-options "--fuel 0 --ifuel 0 --z3rlimit 300" open FStar.Mul let lemma_blocki_aux2 (a:blake_alg) (s1 s2:bytes) (nb1 nb2:nat) (i:nat{i < nb2}) : Lemma (requires S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a) (ensures Spec.Blake2.get_blocki (to_blake_alg a) s2 i == Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) (i + nb1)) = let s = s1 `S.append` s2 in let a' = to_blake_alg a in calc (==) { Spec.Blake2.get_blocki a' s (i + nb1); (==) { } S.slice s ((i + nb1) * block_length a) ((i + nb1 + 1) * block_length a); (==) { } S.slice s (i * block_length a + nb1 * block_length a) ((i + 1) * block_length a + nb1 * block_length a); (==) { } S.slice s (i * block_length a + S.length s1) ((i + 1) * block_length a + S.length s1); (==) { S.slice_slice s (S.length s1) (S.length s) (i * block_length a) ((i+1) * block_length a) } S.slice (S.slice s (S.length s1) (S.length s)) (i * block_length a) ((i+1) * block_length a); (==) { S.append_slices s1 s2; assert (s2 `S.equal` S.slice s (S.length s1) (S.length s)) } S.slice s2 (i * block_length a) ((i+1) * block_length a); (==) { } Spec.Blake2.get_blocki a' s2 i; } let lemma_update_aux2 (a:blake_alg) (s1 s2:bytes) (nb1 nb2:nat) (prevlen1 prevlen2:nat) (i:nat{i < nb2}) (acc:words_state a) : Lemma (requires S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a /\ prevlen1 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length s1 /\ (S.length (S.append s1 s2) + prevlen1) `less_than_max_input_length` a) (ensures Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen1 (s1 `S.append` s2) (i + nb1) acc == Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen2 s2 i acc) = let s = s1 `S.append` s2 in let a' = to_blake_alg a in let open Spec.Blake2 in let f1 = blake2_update1 (to_blake_alg a) prevlen1 s in let f2 = blake2_update1 (to_blake_alg a) prevlen2 s2 in let totlen1 = prevlen1 + (i + nb1 + 1) * size_block a' in let totlen2 = prevlen2 + (i + 1) * size_block a' in // Proving totlen1 == totlen2 for the last calc step below calc (==) { totlen2; (==) { } prevlen2 + (i + 1) * block_length a; (==) { } prevlen1 + S.length s1 + (i + 1) * block_length a; (==) { } prevlen1 + nb1 * block_length a + (i + 1) * block_length a; (==) { Math.Lemmas.distributivity_add_left (i + 1) nb1 (block_length a) } prevlen1 + (i + 1 + nb1) * block_length a; (==) { } totlen1; }; calc (==) { f1 (i + nb1) acc; (==) { } blake2_update_block a' false totlen1 (get_blocki a' s (i + nb1)) acc; (==) { lemma_blocki_aux2 a s1 s2 nb1 nb2 i } blake2_update_block a' false totlen1 (get_blocki a' s2 i) acc; (==) { } f2 i acc; }
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Spec.Hash.Lemmas.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": 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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.blake_alg -> h: Spec.Hash.Definitions.words_state a -> prevlen1: Prims.nat -> prevlen2: Prims.nat -> input1: Spec.Hash.Definitions.bytes -> input2: Spec.Hash.Definitions.bytes -> FStar.Pervasives.Lemma (requires prevlen1 % Spec.Hash.Definitions.block_length a = 0 /\ FStar.Seq.Base.length input1 % Spec.Hash.Definitions.block_length a == 0 /\ FStar.Seq.Base.length input2 % Spec.Hash.Definitions.block_length a == 0 /\ prevlen2 = prevlen1 + FStar.Seq.Base.length input1 /\ Spec.Agile.Hash.update_multi_pre a prevlen1 (FStar.Seq.Base.append input1 input2)) (ensures (let input = FStar.Seq.Base.append input1 input2 in FStar.Seq.Base.length input % Spec.Hash.Definitions.block_length a == 0 /\ Spec.Agile.Hash.update_multi_pre a prevlen1 input1 /\ Spec.Agile.Hash.update_multi_pre a prevlen2 input2 /\ Spec.Agile.Hash.update_multi a (Spec.Agile.Hash.update_multi a h prevlen1 input1) prevlen2 input2 == Spec.Agile.Hash.update_multi a h prevlen1 input))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Hash.Definitions.blake_alg", "Spec.Hash.Definitions.words_state", "Prims.nat", "Spec.Hash.Definitions.bytes", "FStar.Calc.calc_finish", "Prims.eq2", "Spec.Agile.Hash.update_multi", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.LoopCombinators.repeat_right", "Lib.LoopCombinators.repeati", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Lib.LoopCombinators.repeati_def", "Spec.Blake2.Definitions.state", "Lib.LoopCombinators.repeat_right_plus", "Lib.Sequence.Lemmas.repeati_extensionality", "FStar.Classical.forall_intro_2", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.Lemmas.repeat_gen_right_extensionality", "Prims.op_Addition", "Lib.LoopCombinators.fixed_a", "Prims.l_True", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.Blake2.Definitions.wt", "Lib.IntTypes.SEC", "FStar.Pervasives.pattern", "Spec.Hash.Lemmas.lemma_update_aux2", "Spec.Hash.Lemmas.lemma_blocki_aux1", "Prims.l_and", "Prims.op_Division", "Lib.Sequence.length", "Lib.IntTypes.U8", "Spec.Blake2.Definitions.size_block", "Prims.op_LessThanOrEqual", "Spec.Blake2.Definitions.max_limb", "Spec.Blake2.blake2_update1", "Spec.Blake2.Definitions.alg", "Spec.Hash.Definitions.to_blake_alg", "Prims.int", "FStar.Seq.Base.length", "Lib.IntTypes.uint8", "Spec.Hash.Definitions.block_length", "FStar.Seq.Base.seq", "FStar.Seq.Base.append", "Prims.op_Modulus", "Prims.op_Equality", "Spec.Agile.Hash.update_multi_pre" ]
[]
false
false
true
false
false
let update_multi_associative_blake (a: blake_alg) (h: words_state a) (prevlen1 prevlen2: nat) (input1 input2: bytes) : Lemma (requires (prevlen1 % block_length a == 0 /\ S.length input1 % block_length a == 0 /\ S.length input2 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length input1 /\ update_multi_pre a prevlen1 (S.append input1 input2))) (ensures (let input = S.append input1 input2 in S.length input % block_length a == 0 /\ update_multi_pre a prevlen1 input1 /\ update_multi_pre a prevlen2 input2 /\ update_multi a (update_multi a h prevlen1 input1) prevlen2 input2 == update_multi a h prevlen1 input)) =
let input = S.append input1 input2 in let nb1 = S.length input1 / block_length a in let nb2 = S.length input2 / block_length a in let nb = S.length input / block_length a in let a' = to_blake_alg a in let f = Spec.Blake2.blake2_update1 a' prevlen1 input in let f1 = Spec.Blake2.blake2_update1 a' prevlen1 input1 in let f2 = Spec.Blake2.blake2_update1 a' prevlen2 input2 in let aux1 (i: nat{i < nb1}) (acc: words_state a) : Lemma (f i acc == f1 i acc) = lemma_blocki_aux1 a input1 input2 i in let open FStar.Mul in let aux2 (i: nat{i < nb2}) (acc: words_state a) : Lemma (f (i + nb1) acc == f2 i acc) = lemma_update_aux2 a input1 input2 nb1 nb2 prevlen1 prevlen2 i acc in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in let fix = fixed_a (words_state a) in calc ( == ) { update_multi a h prevlen1 input; ( == ) { () } repeati #(words_state a) nb f h; ( == ) { repeati_def nb f h } repeat_right 0 nb fix f h; ( == ) { (repeat_right_plus 0 nb1 nb fix f h; repeati_def nb1 f h) } repeat_right nb1 nb fix f (repeati nb1 f h); ( == ) { (Classical.forall_intro_2 aux1; repeati_extensionality nb1 f f1 h) } repeat_right nb1 nb fix f (update_multi a h prevlen1 input1); ( == ) { (Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 fix fix f2 f (update_multi a h prevlen1 input1)) } repeat_right 0 nb2 fix f2 (update_multi a h prevlen1 input1); ( == ) { repeati_def nb2 f2 (update_multi a h prevlen1 input1) } update_multi a (update_multi a h prevlen1 input1) prevlen2 input2; }
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_init
val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0)))
val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0)))
let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame()
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 128, "start_col": 0, "start_line": 119 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0)))
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ctx: Hacl.Impl.Chacha20.Core32xN.state w -> k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul -> ctr0: Lib.IntTypes.size_t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Hacl.Impl.Chacha20.Core32xN.state", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.op_Array_Assignment", "Hacl.Impl.Chacha20.Core32xN.uint32xN", "Lib.IntVector.op_Plus_Bar", "Lib.IntTypes.U32", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Lib.IntVector.vec_t", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntVector.vec_v", "Lib.Sequence.createi", "Lib.IntTypes.mk_int", "Lib.IntVector.vec_counter", "Lib.Buffer.mapT", "Lib.IntTypes.uint32", "Hacl.Spec.Chacha20.Vec.vec_load_i", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Chacha20.Vec.setup1", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u32", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let chacha20_init #w ctx k n ctr =
push_frame (); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get () in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame ()
false
MerkleTree.Low.fst
MerkleTree.Low.mt_get_root
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))))
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))))
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
{ "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": 5, "end_line": 1682, "start_col": 0, "start_line": 1571 }
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))))
{ "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": 150, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.const_mt_p -> rt: 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.const_mt_p", "MerkleTree.Low.Datastructures.hash", "FStar.Ghost.reveal", "MerkleTree.Low.__proj__MT__item__rhs_ok", "Prims._assert", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "MerkleTree.New.High.merkle_tree", "FStar.UInt32.v", "MerkleTree.Low.__proj__MT__item__hash_size", "LowStar.Monotonic.Buffer.get", "MerkleTree.Low.merkle_tree", "LowStar.Buffer.trivial_preorder", "MerkleTree.New.High.hash", "MerkleTree.New.High.mt_get_root", "MerkleTree.Low.mt_lift", "LowStar.Regional.__proj__Rgl__item__r_repr", "MerkleTree.Low.Datastructures.hreg", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "MerkleTree.New.High.mt_get_root_rhs_ok_true", "MerkleTree.Low.mt_preserved", "LowStar.Monotonic.Buffer.loc_all_regions_from", "LowStar.Regional.__proj__Rgl__item__region_of", "MerkleTree.Low.mt_safe_preserved", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.RVector.__proj__Cpy__item__copy", "MerkleTree.Low.Datastructures.hcpy", "Prims.bool", "MerkleTree.New.High.MT", "LowStar.RVector.as_seq", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Datastructures.hvreg", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.mt_get_root_rhs_ok_false", "MerkleTree.Low.mt_safe", "MerkleTree.Low.mt_safe_elts_preserved", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.Regional.__proj__Rgl__item__r_sep", "LowStar.RVector.as_seq_preserved", "LowStar.RVector.rv_inv_preserved", "LowStar.BufferOps.op_Star_Equals", "MerkleTree.Low.MT", "LowStar.Regional.__proj__Rgl__item__repr", "LowStar.Monotonic.Buffer.frameOf", "Lib.IntTypes.uint8", "LowStar.Monotonic.Buffer.modifies_buffer_elim", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.construct_rhs", "LowStar.Regional.regional", "MerkleTree.Low.Datastructures.hash_vv", "MerkleTree.Low.Datastructures.hvvreg", "MerkleTree.Low.mt_safe_elts_spec", "LowStar.Monotonic.Buffer.loc_union", "LowStar.RVector.loc_rvector", "LowStar.Vector.loc_vector_within_included", "LowStar.Vector.size_of", "LowStar.Monotonic.Buffer.live", "LowStar.Regional.__proj__Rgl__item__r_inv", "LowStar.RVector.rv_inv", "MerkleTree.Low.construct_rhs", "MerkleTree.Low.Hashfunctions.hash_fun_t", "MerkleTree.Low.__proj__MT__item__hash_spec", "MerkleTree.Low.__proj__MT__item__hash_fun", "MerkleTree.Low.__proj__MT__item__mroot", "LowStar.Vector.uint32_t", "MerkleTree.Low.merkle_tree_size_lg", "MerkleTree.Low.__proj__MT__item__rhs", "MerkleTree.Low.__proj__MT__item__hs", "MerkleTree.Low.index_t", "Prims.l_and", "FStar.UInt32.lte", "MerkleTree.Low.__proj__MT__item__i", "MerkleTree.Low.add64_fits", "MerkleTree.Low.__proj__MT__item__offset", "MerkleTree.Low.__proj__MT__item__j", "MerkleTree.Low.offset_t", "LowStar.BufferOps.op_Bang_Star", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.ConstBuffer.cast" ]
[]
false
true
false
false
false
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 (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))) else (construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun; let hh1 = HST.get () in 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; 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 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; 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 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); 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)))
false
Steel.ST.PCMReference.fsti
Steel.ST.PCMReference.pts_to_not_null
val pts_to_not_null (#opened: _) (#t: Type) (#p: pcm t) (r: ref t p) (v: t) : STGhost unit opened (pts_to r v) (fun _ -> pts_to r v) True (fun _ -> r =!= null)
val pts_to_not_null (#opened: _) (#t: Type) (#p: pcm t) (r: ref t p) (v: t) : STGhost unit opened (pts_to r v) (fun _ -> pts_to r v) True (fun _ -> r =!= null)
let pts_to_not_null (#opened: _) (#t: Type) (#p: pcm t) (r: ref t p) (v: t) : STGhost unit opened (pts_to r v) (fun _ -> pts_to r v) True (fun _ -> r =!= null) = extract_fact (pts_to r v) (r =!= null) (fun m -> pts_to_not_null r v m)
{ "file_name": "lib/steel/Steel.ST.PCMReference.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 49, "start_col": 0, "start_line": 35 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.PCMReference open FStar.PCM open FStar.Ghost open Steel.ST.Util /// This module exposes the core PCM-based memory model defined in Steel.Memory /// as stateful Steel computations. #set-options "--ide_id_info_off" /// Lifting the pts_to separation logic, PCM-indexed predicate to a vprop. /// Its selector is non-informative (it is unit) [@@ __steel_reduce__] unfold let pts_to (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v:a) = to_vprop (pts_to r v)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.PCMReference.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.Memory.ref t p -> v: t -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "FStar.PCM.pcm", "Steel.Memory.ref", "Steel.ST.Effect.Ghost.extract_fact", "Steel.ST.PCMReference.pts_to", "Prims.l_not", "Prims.eq2", "Steel.Memory.null", "Steel.Memory.mem", "Steel.Memory.pts_to_not_null", "Prims.unit", "Steel.Effect.Common.vprop", "Prims.l_True" ]
[]
false
true
false
false
false
let pts_to_not_null (#opened: _) (#t: Type) (#p: pcm t) (r: ref t p) (v: t) : STGhost unit opened (pts_to r v) (fun _ -> pts_to r v) True (fun _ -> r =!= null) =
extract_fact (pts_to r v) (r =!= null) (fun m -> pts_to_not_null r v m)
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_encrypt_last
val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text)))
val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text)))
let chacha20_encrypt_last #w ctx len out incr text = push_frame(); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame()
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 171, "start_col": 0, "start_line": 165 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame() noextract val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text)))
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ctx: Hacl.Impl.Chacha20.Core32xN.state w -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len < w * 64} -> out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> incr: Lib.IntTypes.size_t{w * Lib.IntTypes.v incr <= Lib.IntTypes.max_size_t} -> text: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Hacl.Impl.Chacha20.Core32xN.state", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.Mul.op_Star", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.copy", "Lib.Buffer.MUT", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Chacha20.Vec.chacha20_encrypt_block", "Lib.Buffer.update_sub", "Lib.IntTypes.mul", "Lib.IntTypes.mk_int", "Lib.Buffer.create", "Lib.IntTypes.u8", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let chacha20_encrypt_last #w ctx len out incr text =
push_frame (); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame ()
false
Trees.fst
Trees.insert_avl_proof_aux
val insert_avl_proof_aux (#a: Type) (cmp: cmp a) (x: avl a cmp) (key root: a) : Lemma (requires is_avl cmp x) (ensures (let res = insert_avl cmp x key in is_avl cmp res /\ height x <= height res /\ height res <= height x + 1 /\ (forall_keys x (key_left cmp root) /\ key_left cmp root key ==> forall_keys res (key_left cmp root)) /\ (forall_keys x (key_right cmp root) /\ key_right cmp root key ==> forall_keys res (key_right cmp root))))
val insert_avl_proof_aux (#a: Type) (cmp: cmp a) (x: avl a cmp) (key root: a) : Lemma (requires is_avl cmp x) (ensures (let res = insert_avl cmp x key in is_avl cmp res /\ height x <= height res /\ height res <= height x + 1 /\ (forall_keys x (key_left cmp root) /\ key_left cmp root key ==> forall_keys res (key_left cmp root)) /\ (forall_keys x (key_right cmp root) /\ key_right cmp root key ==> forall_keys res (key_right cmp root))))
let rec insert_avl_proof_aux (#a: Type) (cmp:cmp a) (x: avl a cmp) (key: a) (root:a) : Lemma (requires is_avl cmp x) (ensures ( let res = insert_avl cmp x key in is_avl cmp res /\ height x <= height res /\ height res <= height x + 1 /\ (forall_keys x (key_left cmp root) /\ key_left cmp root key ==> forall_keys res (key_left cmp root)) /\ (forall_keys x (key_right cmp root) /\ key_right cmp root key ==> forall_keys res (key_right cmp root))) ) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then ( let new_left = insert_avl cmp left key in let tmp = Node data new_left right in insert_avl_proof_aux cmp left key data; // Need this one for propagating that all elements are smaller than root insert_avl_proof_aux cmp left key root; rebalance_avl_proof cmp tmp root ) else ( let new_right = insert_avl cmp right key in let tmp = Node data left new_right in insert_avl_proof_aux cmp right key data; insert_avl_proof_aux cmp right key root; rebalance_avl_proof cmp tmp root )
{ "file_name": "share/steel/examples/steel/Trees.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 543, "start_col": 0, "start_line": 508 }
module Trees module M = FStar.Math.Lib #set-options "--fuel 1 --ifuel 1 --z3rlimit 20" (*** Type definitions *) (**** The tree structure *) type tree (a: Type) = | Leaf : tree a | Node: data: a -> left: tree a -> right: tree a -> tree a (**** Binary search trees *) type node_data (a b: Type) = { key: a; payload: b; } let kv_tree (a: Type) (b: Type) = tree (node_data a b) type cmp (a: Type) = compare: (a -> a -> int){ squash (forall x. compare x x == 0) /\ squash (forall x y. compare x y > 0 <==> compare y x < 0) /\ squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0) } let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool = match t with | Leaf -> true | Node data left right -> cond data && forall_keys left cond && forall_keys right cond let key_left (#a: Type) (compare:cmp a) (root key: a) = compare root key >= 0 let key_right (#a: Type) (compare : cmp a) (root key: a) = compare root key <= 0 let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) && forall_keys right (key_right compare data) let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} (*** Operations *) (**** Lookup *) let rec mem (#a: Type) (r: tree a) (x: a) : prop = match r with | Leaf -> False | Node data left right -> (data == x) \/ (mem right x) \/ mem left x let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a = match x with | Leaf -> None | Node data left right -> let delta = cmp data key in if delta < 0 then bst_search cmp right key else if delta > 0 then bst_search cmp left key else Some data (**** Height *) let rec height (#a: Type) (x: tree a) : nat = match x with | Leaf -> 0 | Node data left right -> if height left > height right then (height left) + 1 else (height right) + 1 (**** Append *) let rec append_left (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x (append_left left v) right let rec append_right (#a: Type) (x: tree a) (v: a) : tree a = match x with | Leaf -> Node v Leaf Leaf | Node x left right -> Node x left (append_right right v) (**** Insertion *) (**** BST insertion *) let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then begin let new_left = insert_bst cmp left key in Node data new_left right end else begin let new_right = insert_bst cmp right key in Node data left new_right end let rec insert_bst_preserves_forall_keys (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) (cond: a -> bool) : Lemma (requires (forall_keys x cond /\ cond key)) (ensures (forall_keys (insert_bst cmp x key) cond)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then insert_bst_preserves_forall_keys cmp left key cond else insert_bst_preserves_forall_keys cmp right key cond let rec insert_bst_preserves_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : Lemma(is_bst cmp (insert_bst cmp x key)) = match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then begin insert_bst_preserves_forall_keys cmp left key (key_left cmp data); insert_bst_preserves_bst cmp left key end else begin insert_bst_preserves_forall_keys cmp right key (key_right cmp data); insert_bst_preserves_bst cmp right key end (**** AVL insertion *) let rec is_balanced (#a: Type) (x: tree a) : bool = match x with | Leaf -> true | Node data left right -> M.abs(height right - height left) <= 1 && is_balanced(right) && is_balanced(left) let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop = is_bst cmp x /\ is_balanced x let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} let rotate_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z t2 t3) -> Some (Node z (Node x t1 t2) t3) | _ -> None let rotate_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 t2) t3 -> Some (Node z t1 (Node x t2 t3)) | _ -> None let rotate_right_left (#a: Type) (r: tree a) : option (tree a) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> Some (Node y (Node x t1 t2) (Node z t3 t4)) | _ -> None let rotate_left_right (#a: Type) (r: tree a) : option (tree a) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> Some (Node y (Node z t1 t2) (Node x t3 t4)) | _ -> None (** rotate preserves bst *) let rec forall_keys_trans (#a: Type) (t: tree a) (cond1 cond2: a -> bool) : Lemma (requires (forall x. cond1 x ==> cond2 x) /\ forall_keys t cond1) (ensures forall_keys t cond2) = match t with | Leaf -> () | Node data left right -> forall_keys_trans left cond1 cond2; forall_keys_trans right cond1 cond2 let rotate_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left r)) (ensures is_bst cmp (Some?.v (rotate_left r))) = match r with | Node x t1 (Node z t2 t3) -> assert (is_bst cmp (Node z t2 t3)); assert (is_bst cmp (Node x t1 t2)); forall_keys_trans t1 (key_left cmp x) (key_left cmp z) let rotate_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right r)) (ensures is_bst cmp (Some?.v (rotate_right r))) = match r with | Node x (Node z t1 t2) t3 -> assert (is_bst cmp (Node z t1 t2)); assert (is_bst cmp (Node x t2 t3)); forall_keys_trans t3 (key_right cmp x) (key_right cmp z) let rotate_right_left_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_right_left r)) (ensures is_bst cmp (Some?.v (rotate_right_left r))) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (is_bst cmp (Node z (Node y t2 t3) t4)); assert (is_bst cmp (Node y t2 t3)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys (Node y t2 t3) (key_right cmp x)); assert (forall_keys t2 (key_right cmp x)); assert (is_bst cmp left); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp x) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp z) (key_right cmp y); assert (forall_keys right (key_right cmp y)) let rotate_left_right_bst (#a:Type) (cmp:cmp a) (r:tree a) : Lemma (requires is_bst cmp r /\ Some? (rotate_left_right r)) (ensures is_bst cmp (Some?.v (rotate_left_right r))) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (is_bst cmp (Node z t1 (Node y t2 t3))); assert (is_bst cmp (Node y t2 t3)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (is_bst cmp left); assert (forall_keys (Node y t2 t3) (key_left cmp x)); assert (forall_keys t2 (key_left cmp x)); assert (is_bst cmp right); forall_keys_trans t1 (key_left cmp z) (key_left cmp y); assert (forall_keys left (key_left cmp y)); forall_keys_trans t4 (key_right cmp x) (key_right cmp y); assert (forall_keys right (key_right cmp y)) (** Same elements before and after rotate **) let rotate_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_left cmp root)); assert (forall_keys (Node x t1 t2) (key_left cmp root)) let rotate_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left r)) (ensures forall_keys (Some?.v (rotate_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z t2 t3) -> assert (forall_keys (Node z t2 t3) (key_right cmp root)); assert (forall_keys (Node x t1 t2) (key_right cmp root)) let rotate_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_left cmp root)); assert (forall_keys (Node x t2 t3) (key_left cmp root)) let rotate_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right r)) (ensures forall_keys (Some?.v (rotate_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 t2) t3 -> assert (forall_keys (Node z t1 t2) (key_right cmp root)); assert (forall_keys (Node x t2 t3) (key_right cmp root)) let rotate_right_left_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_left cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_right_left_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_right_left r)) (ensures forall_keys (Some?.v (rotate_right_left r)) (key_right cmp root)) = match r with | Node x t1 (Node z (Node y t2 t3) t4) -> assert (forall_keys (Node z (Node y t2 t3) t4) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node x t1 t2 in let right = Node z t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) let rotate_left_right_key_left (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_left cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_left cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_left cmp root)); assert (forall_keys (Node y t2 t3) (key_left cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_left cmp root)); assert (forall_keys right (key_left cmp root)) let rotate_left_right_key_right (#a:Type) (cmp:cmp a) (r:tree a) (root:a) : Lemma (requires forall_keys r (key_right cmp root) /\ Some? (rotate_left_right r)) (ensures forall_keys (Some?.v (rotate_left_right r)) (key_right cmp root)) = match r with | Node x (Node z t1 (Node y t2 t3)) t4 -> // Node y (Node z t1 t2) (Node x t3 t4) assert (forall_keys (Node z t1 (Node y t2 t3)) (key_right cmp root)); assert (forall_keys (Node y t2 t3) (key_right cmp root)); let left = Node z t1 t2 in let right = Node x t3 t4 in assert (forall_keys left (key_right cmp root)); assert (forall_keys right (key_right cmp root)) (** Balancing operation for AVLs *) let rebalance_avl (#a: Type) (x: tree a) : tree a = match x with | Leaf -> x | Node data left right -> if is_balanced x then x else ( if height left - height right > 1 then ( let Node ldata lleft lright = left in if height lright > height lleft then ( match rotate_left_right x with | Some y -> y | _ -> x ) else ( match rotate_right x with | Some y -> y | _ -> x ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( match rotate_right_left x with | Some y -> y | _ -> x ) else ( match rotate_left x with | Some y -> y | _ -> x ) ) else ( x ) ) let rebalance_avl_proof (#a: Type) (cmp:cmp a) (x: tree a) (root:a) : Lemma (requires is_bst cmp x /\ ( match x with | Leaf -> True | Node data left right -> is_balanced left /\ is_balanced right /\ height left - height right <= 2 /\ height right - height left <= 2 ) ) (ensures is_avl cmp (rebalance_avl x) /\ (forall_keys x (key_left cmp root) ==> forall_keys (rebalance_avl x) (key_left cmp root)) /\ (forall_keys x (key_right cmp root) ==> forall_keys (rebalance_avl x) (key_right cmp root)) ) = match x with | Leaf -> () | Node data left right -> let x_f = rebalance_avl x in let Node f_data f_left f_right = x_f in if is_balanced x then () else ( if height left - height right > 1 then ( assert (height left = height right + 2); let Node ldata lleft lright = left in if height lright > height lleft then ( assert (height left = height lright + 1); rotate_left_right_bst cmp x; Classical.move_requires (rotate_left_right_key_left cmp x) root; Classical.move_requires (rotate_left_right_key_right cmp x) root; let Node y t2 t3 = lright in let Node x (Node z t1 (Node y t2 t3)) t4 = x in assert (f_data == y); assert (f_left == Node z t1 t2); assert (f_right == Node x t3 t4); assert (lright == Node y t2 t3); // Left part assert (is_balanced lright); assert (height t1 - height t2 <= 1); assert (height t2 - height t1 <= 1); assert (is_balanced t1); assert (is_balanced (Node y t2 t3)); assert (is_balanced t2); assert (is_balanced f_left); // Right part assert (height t3 - height t4 <= 1); assert (height t4 - height t3 <= 1); assert (is_balanced t3); assert (is_balanced t4); assert (is_balanced f_right) ) else ( rotate_right_bst cmp x; Classical.move_requires (rotate_right_key_left cmp x) root; Classical.move_requires (rotate_right_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) else if height left - height right < -1 then ( let Node rdata rleft rright = right in if height rleft > height rright then ( rotate_right_left_bst cmp x; Classical.move_requires (rotate_right_left_key_left cmp x) root; Classical.move_requires (rotate_right_left_key_right cmp x) root; let Node x t1 (Node z (Node y t2 t3) t4) = x in assert (f_data == y); assert (f_left == Node x t1 t2); assert (f_right == Node z t3 t4); // Right part assert (is_balanced rleft); assert (height t3 - height t4 <= 1); assert (height t4 - height t4 <= 1); assert (is_balanced (Node y t2 t3)); assert (is_balanced f_right); // Left part assert (is_balanced t1); assert (is_balanced t2); assert (is_balanced f_left) ) else ( rotate_left_bst cmp x; Classical.move_requires (rotate_left_key_left cmp x) root; Classical.move_requires (rotate_left_key_right cmp x) root; assert (is_balanced f_left); assert (is_balanced f_right); assert (is_balanced x_f) ) ) ) (** Insertion **) let rec insert_avl (#a: Type) (cmp:cmp a) (x: tree a) (key: a) : tree a = match x with | Leaf -> Node key Leaf Leaf | Node data left right -> let delta = cmp data key in if delta >= 0 then ( let new_left = insert_avl cmp left key in let tmp = Node data new_left right in rebalance_avl tmp ) else ( let new_right = insert_avl cmp right key in let tmp = Node data left new_right in rebalance_avl tmp ) #push-options "--z3rlimit 50"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Trees.fst" }
[ { "abbrev": true, "full_module": "FStar.Math.Lib", "short_module": "M" }, { "abbrev": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cmp: Trees.cmp a -> x: Trees.avl a cmp -> key: a -> root: a -> FStar.Pervasives.Lemma (requires Trees.is_avl cmp x) (ensures (let res = Trees.insert_avl cmp x key in Trees.is_avl cmp res /\ Trees.height x <= Trees.height res /\ Trees.height res <= Trees.height x + 1 /\ (Trees.forall_keys x (Trees.key_left cmp root) /\ Trees.key_left cmp root key ==> Trees.forall_keys res (Trees.key_left cmp root)) /\ (Trees.forall_keys x (Trees.key_right cmp root) /\ Trees.key_right cmp root key ==> Trees.forall_keys res (Trees.key_right cmp root))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Trees.cmp", "Trees.avl", "Trees.tree", "Prims.op_GreaterThanOrEqual", "Trees.rebalance_avl_proof", "Prims.unit", "Trees.insert_avl_proof_aux", "Trees.Node", "Trees.insert_avl", "Prims.bool", "Prims.int", "Trees.is_avl", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Trees.height", "Prims.op_Addition", "Prims.l_imp", "Trees.forall_keys", "Trees.key_left", "Trees.key_right", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec insert_avl_proof_aux (#a: Type) (cmp: cmp a) (x: avl a cmp) (key root: a) : Lemma (requires is_avl cmp x) (ensures (let res = insert_avl cmp x key in is_avl cmp res /\ height x <= height res /\ height res <= height x + 1 /\ (forall_keys x (key_left cmp root) /\ key_left cmp root key ==> forall_keys res (key_left cmp root)) /\ (forall_keys x (key_right cmp root) /\ key_right cmp root key ==> forall_keys res (key_right cmp root)))) =
match x with | Leaf -> () | Node data left right -> let delta = cmp data key in if delta >= 0 then (let new_left = insert_avl cmp left key in let tmp = Node data new_left right in insert_avl_proof_aux cmp left key data; insert_avl_proof_aux cmp left key root; rebalance_avl_proof cmp tmp root) else (let new_right = insert_avl cmp right key in let tmp = Node data left new_right in insert_avl_proof_aux cmp right key data; insert_avl_proof_aux cmp right key root; rebalance_avl_proof cmp tmp root)
false
MerkleTree.Low.fst
MerkleTree.Low.mt_flush
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))
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))
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
{ "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": 19, "end_line": 2525, "start_col": 0, "start_line": 2516 }
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))
{ "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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.mt_p -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.mt_p", "MerkleTree.Low.mt_flush_to", "Prims.unit", "MerkleTree.Low.offset_t", "Prims.b2t", "MerkleTree.Low.offsets_connect", "MerkleTree.Low.join_offset", "Prims._assert", "FStar.UInt.fits", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.UInt64.v", "FStar.UInt32.v", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W64", "MerkleTree.Low.uint64_max", "FStar.Integers.W32", "MerkleTree.Low.uint32_32_max", "FStar.Integers.int_t", "FStar.Integers.op_Subtraction", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.index_t", "Prims.l_and", "FStar.UInt32.lte", "MerkleTree.Low.__proj__MT__item__i", "MerkleTree.Low.add64_fits", "MerkleTree.Low.__proj__MT__item__offset", "MerkleTree.Low.__proj__MT__item__j", "MerkleTree.Low.merkle_tree", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder" ]
[]
false
true
false
false
false
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
false
TwoLockQueue.fst
TwoLockQueue.rewrite
val rewrite (#u: _) (p q: vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True)
val rewrite (#u: _) (p q: vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True)
let rewrite #u (p q:vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) = rewrite_slprop p q (fun _ -> reveal_equiv p q)
{ "file_name": "share/steel/examples/steel/TwoLockQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 50, "end_line": 58, "start_col": 0, "start_line": 54 }
module TwoLockQueue open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock module L = FStar.List.Tot module U = Steel.Utils module Q = Queue /// This module provides an implementation of Michael and Scott's two lock queue, using the /// abstract interface for queues provided in Queue.fsti. /// This implementation allows an enqueue and a dequeue operation to safely operate in parallel. /// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation, /// ensuring that at most one enqueue (resp. dequeue) is happening at any time /// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue #push-options "--ide_id_info_off" /// Adding the definition of the vprop equivalence to the context, for proof purposes let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) = Classical.forall_intro_2 reveal_equiv (* Some wrappers to reduce clutter in the code *) [@@__reduce__] let full = full_perm [@@__reduce__] let half = half_perm full (* Wrappers around fst and snd to avoid overnormalization. TODO: The frame inference tactic should not normalize fst and snd *) let fst x = fst x let snd x = snd x (* Some wrappers around Steel functions which are easier to use inside this module *) let ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1}) (x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r p x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1) = let _ = ghost_gather_pt #a #u #p0 #p1 r in ()
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Queue.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "TwoLockQueue.fst" }
[ { "abbrev": true, "full_module": "Queue", "short_module": "Q" }, { "abbrev": true, "full_module": "Steel.Utils", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": 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: Steel.Effect.Common.vprop -> q: Steel.Effect.Common.vprop -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.Effect.Common.vprop", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Memory.mem", "Steel.Effect.Common.reveal_equiv", "Prims.unit", "Steel.Effect.Common.rmem", "Steel.Effect.Common.equiv", "Prims.l_True" ]
[]
false
true
false
false
false
let rewrite #u (p: vprop) (q: vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) =
rewrite_slprop p q (fun _ -> reveal_equiv p q)
false
IfcTypechecker.fst
IfcTypechecker.tc_exp
val tc_exp : env:label_fun -> e:exp -> Pure label (requires True) (ensures ni_exp env e)
val tc_exp : env:label_fun -> e:exp -> Pure label (requires True) (ensures ni_exp env e)
let rec tc_exp env e = match e with | AInt i -> aint_exp env i ; Low | AVar r -> avar_exp env r ; env r | AOp o e1 e2 -> let l1 = tc_exp env e1 in let l2 = tc_exp env e2 in let l = join l1 l2 in sub_exp env e1 l1 l ; sub_exp env e2 l2 l ; binop_exp env o e1 e2 l ; l
{ "file_name": "examples/rel/IfcTypechecker.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 75, "end_line": 32, "start_col": 0, "start_line": 24 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcTypechecker open WhileReify open IfcRulesReify open FStar.DM4F.Exceptions (* Typechecking expressions: we infer the label *)
{ "checked_file": "/", "dependencies": [ "WhileReify.fst.checked", "prims.fst.checked", "IfcRulesReify.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.fst.checked", "FStar.DM4F.Exceptions.fst.checked" ], "interface_file": false, "source_file": "IfcTypechecker.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.Exceptions", "short_module": null }, { "abbrev": false, "full_module": "IfcRulesReify", "short_module": null }, { "abbrev": false, "full_module": "WhileReify", "short_module": null }, { "abbrev": 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
env: IfcRulesReify.label_fun -> e: WhileReify.exp -> Prims.Pure IfcRulesReify.label
Prims.Pure
[]
[]
[ "IfcRulesReify.label_fun", "WhileReify.exp", "Prims.int", "IfcRulesReify.Low", "Prims.unit", "IfcRulesReify.aint_exp", "FStar.DM4F.Heap.IntStoreFixed.id", "IfcRulesReify.avar_exp", "WhileReify.binop", "IfcRulesReify.binop_exp", "IfcRulesReify.sub_exp", "IfcRulesReify.label", "IfcRulesReify.join", "IfcTypechecker.tc_exp" ]
[ "recursion" ]
false
false
false
false
false
let rec tc_exp env e =
match e with | AInt i -> aint_exp env i; Low | AVar r -> avar_exp env r; env r | AOp o e1 e2 -> let l1 = tc_exp env e1 in let l2 = tc_exp env e2 in let l = join l1 l2 in sub_exp env e1 l1 l; sub_exp env e2 l2 l; binop_exp env o e1 e2 l; l
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.st_comp_typing_inversion
val st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) : (universe_of g st.res st.u & tot_typing g st.pre tm_vprop & x:var{fresh_wrt x g (freevars st.post)} & tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop)
val st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) : (universe_of g st.res st.u & tot_typing g st.pre tm_vprop & x:var{fresh_wrt x g (freevars st.post)} & tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop)
let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |)
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 70, "start_col": 0, "start_line": 68 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit())
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
ct: Pulse.Typing.st_comp_typing g st -> FStar.Pervasives.dtuple4 (Pulse.Typing.universe_of g (Mkst_comp?.res st) (Mkst_comp?.u st)) (fun _ -> Pulse.Typing.tot_typing g (Mkst_comp?.pre st) Pulse.Syntax.Base.tm_vprop) (fun _ _ -> x: Pulse.Syntax.Base.var {Pulse.Typing.fresh_wrt x g (Pulse.Syntax.Naming.freevars (Mkst_comp?.post st))}) (fun _ _ x -> Pulse.Typing.tot_typing (Pulse.Typing.Env.push_binding g x Pulse.Syntax.Base.ppname_default (Mkst_comp?.res st)) (Pulse.Syntax.Naming.open_term (Mkst_comp?.post st) x) Pulse.Syntax.Base.tm_vprop)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.st_comp", "Pulse.Typing.st_comp_typing", "Pulse.Syntax.Base.var", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_None", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.lookup", "Prims.l_not", "FStar.Set.mem", "Pulse.Syntax.Naming.freevars", "Pulse.Syntax.Base.__proj__Mkst_comp__item__post", "Pulse.Typing.universe_of", "Pulse.Syntax.Base.__proj__Mkst_comp__item__res", "Pulse.Syntax.Base.__proj__Mkst_comp__item__u", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.__proj__Mkst_comp__item__pre", "Pulse.Syntax.Base.tm_vprop", "Pulse.Typing.Env.push_binding", "Pulse.Syntax.Base.ppname_default", "Pulse.Syntax.Naming.open_term", "FStar.Pervasives.Mkdtuple4", "Pulse.Typing.fresh_wrt", "FStar.Pervasives.dtuple4" ]
[]
false
false
false
false
false
let st_comp_typing_inversion (#g: env) (#st: _) (ct: st_comp_typing g st) =
let STC g st x ty pre post = ct in (| ty, pre, x, post |)
false
IfcTypechecker.fst
IfcTypechecker.tc_com
val tc_com : env:label_fun -> c:com -> Exn label (requires True) (ensures fun ol -> Inl? ol ==> ni_com env c (Inl?.v ol)) (decreases c)
val tc_com : env:label_fun -> c:com -> Exn label (requires True) (ensures fun ol -> Inl? ol ==> ni_com env c (Inl?.v ol)) (decreases c)
let rec tc_com env c = match c with | Skip -> skip_com env ; High | Assign r e -> let le = tc_exp env e in let lr = env r in if not (le <= lr) then raise Not_well_typed ; sub_exp env e le lr ; assign_com env e r ; lr | Seq c1 c2 -> let l1 = tc_com env c1 in let l2 = tc_com env c2 in let l = meet l1 l2 in sub_com env c1 l1 l ; sub_com env c2 l2 l ; seq_com env c1 c2 l ; l | If e ct cf -> let le = tc_exp env e in let lt = tc_com env ct in let lf = tc_com env cf in if not (le <= lt && le <= lf) then raise Not_well_typed ; let l = meet lt lf in universal_property_meet le lt lf ; sub_exp env e le l ; sub_com env ct lt l ; sub_com env cf lf l ; cond_com env e ct cf l ; l | While e c v -> let le = tc_exp env e in let lc = tc_com env c in if not (le <= lc) then raise Not_well_typed ; sub_exp env e le lc ; while_com env e c v lc ; lc
{ "file_name": "examples/rel/IfcTypechecker.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 85, "start_col": 1, "start_line": 44 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcTypechecker open WhileReify open IfcRulesReify open FStar.DM4F.Exceptions (* Typechecking expressions: we infer the label *) val tc_exp : env:label_fun -> e:exp -> Pure label (requires True) (ensures ni_exp env e) let rec tc_exp env e = match e with | AInt i -> aint_exp env i ; Low | AVar r -> avar_exp env r ; env r | AOp o e1 e2 -> let l1 = tc_exp env e1 in let l2 = tc_exp env e2 in let l = join l1 l2 in sub_exp env e1 l1 l ; sub_exp env e2 l2 l ; binop_exp env o e1 e2 l ; l (* TODO : refine this exception to have some interesting typechecking-error reporting *) exception Not_well_typed #set-options "--z3rlimit 30" (* Typechecking commands: we typecheck in a given context *) val tc_com : env:label_fun -> c:com -> Exn label (requires True) (ensures fun ol -> Inl? ol ==> ni_com env c (Inl?.v ol))
{ "checked_file": "/", "dependencies": [ "WhileReify.fst.checked", "prims.fst.checked", "IfcRulesReify.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.fst.checked", "FStar.DM4F.Exceptions.fst.checked" ], "interface_file": false, "source_file": "IfcTypechecker.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.Exceptions", "short_module": null }, { "abbrev": false, "full_module": "IfcRulesReify", "short_module": null }, { "abbrev": false, "full_module": "WhileReify", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
env: IfcRulesReify.label_fun -> c: WhileReify.com -> FStar.DM4F.Exceptions.Exn IfcRulesReify.label
FStar.DM4F.Exceptions.Exn
[ "" ]
[]
[ "IfcRulesReify.label_fun", "WhileReify.com", "IfcRulesReify.High", "Prims.unit", "IfcRulesReify.skip_com", "IfcRulesReify.label", "FStar.DM4F.Heap.IntStoreFixed.id", "WhileReify.exp", "IfcRulesReify.assign_com", "IfcRulesReify.sub_exp", "Prims.op_Negation", "IfcRulesReify.op_Less_Equals", "FStar.DM4F.Exceptions.raise", "IfcTypechecker.Not_well_typed", "Prims.bool", "IfcTypechecker.tc_exp", "IfcRulesReify.seq_com", "IfcRulesReify.sub_com", "IfcRulesReify.meet", "IfcTypechecker.tc_com", "IfcRulesReify.cond_com", "IfcRulesReify.universal_property_meet", "Prims.op_AmpAmp", "WhileReify.metric", "IfcRulesReify.while_com" ]
[ "recursion" ]
false
true
false
false
false
let rec tc_com env c =
match c with | Skip -> skip_com env; High | Assign r e -> let le = tc_exp env e in let lr = env r in if not (le <= lr) then raise Not_well_typed; sub_exp env e le lr; assign_com env e r; lr | Seq c1 c2 -> let l1 = tc_com env c1 in let l2 = tc_com env c2 in let l = meet l1 l2 in sub_com env c1 l1 l; sub_com env c2 l2 l; seq_com env c1 c2 l; l | If e ct cf -> let le = tc_exp env e in let lt = tc_com env ct in let lf = tc_com env cf in if not (le <= lt && le <= lf) then raise Not_well_typed; let l = meet lt lf in universal_property_meet le lt lf; sub_exp env e le l; sub_com env ct lt l; sub_com env cf lf l; cond_com env e ct cf l; l | While e c v -> let le = tc_exp env e in let lc = tc_com env c in if not (le <= lc) then raise Not_well_typed; sub_exp env e le lc; while_com env e c v lc; lc
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.comp_typing_inversion
val comp_typing_inversion (#g:env) (#c:comp_st) (ct:comp_typing_u g c) : st_comp_typing g (st_comp_of_comp c) & iname_typing g c
val comp_typing_inversion (#g:env) (#c:comp_st) (ct:comp_typing_u g c) : st_comp_typing g (st_comp_of_comp c) & iname_typing g c
let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 63, "start_col": 0, "start_line": 59 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic()
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
ct: Pulse.Typing.comp_typing_u g c -> Pulse.Typing.st_comp_typing g (Pulse.Syntax.Base.st_comp_of_comp c) * Pulse.Typing.Metatheory.Base.iname_typing g c
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.comp_typing_u", "Pulse.Syntax.Base.st_comp", "Pulse.Typing.st_comp_typing", "FStar.Pervasives.Native.Mktuple2", "Pulse.Syntax.Base.st_comp_of_comp", "Pulse.Typing.Metatheory.Base.iname_typing", "Pulse.Typing.Metatheory.Base.emp_inames_typing", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.observability", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.tm_inames", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let comp_typing_inversion #g #c ct =
match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it
false
IfcTypechecker.fst
IfcTypechecker.tc_com_hybrid
val tc_com_hybrid : env:label_fun -> c:com -> list (cl:(com*label){ni_com env (fst cl) (snd cl)}) -> Exn label (requires True) (ensures fun ol -> Inl? ol ==> ni_com env c (Inl?.v ol)) (decreases c)
val tc_com_hybrid : env:label_fun -> c:com -> list (cl:(com*label){ni_com env (fst cl) (snd cl)}) -> Exn label (requires True) (ensures fun ol -> Inl? ol ==> ni_com env c (Inl?.v ol)) (decreases c)
let rec tc_com_hybrid env c cls = match find #(cl:(com*label){ni_com env (fst cl) (snd cl)}) (fun cl -> fst cl = c) cls with | Some (_,l) -> l | None -> (* the rest is copied more or less verbatim from above *) begin match c with | Skip -> skip_com env ; High | Assign r e -> let le = tc_exp env e in let lr = env r in if not (le <= lr) then raise Not_well_typed ; sub_exp env e le lr ; assign_com env e r ; lr | Seq c1 c2 -> let l1 = tc_com_hybrid env c1 cls in let l2 = tc_com_hybrid env c2 cls in let l = meet l1 l2 in sub_com env c1 l1 l ; sub_com env c2 l2 l ; seq_com env c1 c2 l ; l | If e ct cf -> let le = tc_exp env e in let lt = tc_com_hybrid env ct cls in let lf = tc_com_hybrid env cf cls in if not (le <= lt && le <= lf) then raise Not_well_typed ; let l = meet lt lf in universal_property_meet le lt lf ; sub_exp env e le l ; sub_com env ct lt l ; sub_com env cf lf l ; cond_com env e ct cf l ; l | While e c v -> let le = tc_exp env e in let lc = tc_com_hybrid env c cls in if not (le <= lc) then raise Not_well_typed ; sub_exp env e le lc ; while_com env e c v lc ; lc end
{ "file_name": "examples/rel/IfcTypechecker.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 140, "start_col": 1, "start_line": 92 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcTypechecker open WhileReify open IfcRulesReify open FStar.DM4F.Exceptions (* Typechecking expressions: we infer the label *) val tc_exp : env:label_fun -> e:exp -> Pure label (requires True) (ensures ni_exp env e) let rec tc_exp env e = match e with | AInt i -> aint_exp env i ; Low | AVar r -> avar_exp env r ; env r | AOp o e1 e2 -> let l1 = tc_exp env e1 in let l2 = tc_exp env e2 in let l = join l1 l2 in sub_exp env e1 l1 l ; sub_exp env e2 l2 l ; binop_exp env o e1 e2 l ; l (* TODO : refine this exception to have some interesting typechecking-error reporting *) exception Not_well_typed #set-options "--z3rlimit 30" (* Typechecking commands: we typecheck in a given context *) val tc_com : env:label_fun -> c:com -> Exn label (requires True) (ensures fun ol -> Inl? ol ==> ni_com env c (Inl?.v ol)) (decreases c) let rec tc_com env c = match c with | Skip -> skip_com env ; High | Assign r e -> let le = tc_exp env e in let lr = env r in if not (le <= lr) then raise Not_well_typed ; sub_exp env e le lr ; assign_com env e r ; lr | Seq c1 c2 -> let l1 = tc_com env c1 in let l2 = tc_com env c2 in let l = meet l1 l2 in sub_com env c1 l1 l ; sub_com env c2 l2 l ; seq_com env c1 c2 l ; l | If e ct cf -> let le = tc_exp env e in let lt = tc_com env ct in let lf = tc_com env cf in if not (le <= lt && le <= lf) then raise Not_well_typed ; let l = meet lt lf in universal_property_meet le lt lf ; sub_exp env e le l ; sub_com env ct lt l ; sub_com env cf lf l ; cond_com env e ct cf l ; l | While e c v -> let le = tc_exp env e in let lc = tc_com env c in if not (le <= lc) then raise Not_well_typed ; sub_exp env e le lc ; while_com env e c v lc ; lc open FStar.List val tc_com_hybrid : env:label_fun -> c:com -> list (cl:(com*label){ni_com env (fst cl) (snd cl)}) -> Exn label (requires True) (ensures fun ol -> Inl? ol ==> ni_com env c (Inl?.v ol))
{ "checked_file": "/", "dependencies": [ "WhileReify.fst.checked", "prims.fst.checked", "IfcRulesReify.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.fst.checked", "FStar.DM4F.Exceptions.fst.checked" ], "interface_file": false, "source_file": "IfcTypechecker.fst" }
[ { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Exceptions", "short_module": null }, { "abbrev": false, "full_module": "IfcRulesReify", "short_module": null }, { "abbrev": false, "full_module": "WhileReify", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
env: IfcRulesReify.label_fun -> c: WhileReify.com -> cls: Prims.list (cl: (WhileReify.com * IfcRulesReify.label) { IfcRulesReify.ni_com env (FStar.Pervasives.Native.fst cl) (FStar.Pervasives.Native.snd cl) }) -> FStar.DM4F.Exceptions.Exn IfcRulesReify.label
FStar.DM4F.Exceptions.Exn
[ "" ]
[]
[ "IfcRulesReify.label_fun", "WhileReify.com", "Prims.list", "FStar.Pervasives.Native.tuple2", "IfcRulesReify.label", "IfcRulesReify.ni_com", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "FStar.List.Tot.Base.find", "Prims.op_Equality", "Prims.bool", "IfcRulesReify.High", "Prims.unit", "IfcRulesReify.skip_com", "FStar.DM4F.Heap.IntStoreFixed.id", "WhileReify.exp", "IfcRulesReify.assign_com", "IfcRulesReify.sub_exp", "Prims.op_Negation", "IfcRulesReify.op_Less_Equals", "FStar.DM4F.Exceptions.raise", "IfcTypechecker.Not_well_typed", "IfcTypechecker.tc_exp", "IfcRulesReify.seq_com", "IfcRulesReify.sub_com", "IfcRulesReify.meet", "IfcTypechecker.tc_com_hybrid", "IfcRulesReify.cond_com", "IfcRulesReify.universal_property_meet", "Prims.op_AmpAmp", "WhileReify.metric", "IfcRulesReify.while_com" ]
[ "recursion" ]
false
true
false
false
false
let rec tc_com_hybrid env c cls =
match find #(cl: (com * label){ni_com env (fst cl) (snd cl)}) (fun cl -> fst cl = c) cls with | Some (_, l) -> l | None -> match c with | Skip -> skip_com env; High | Assign r e -> let le = tc_exp env e in let lr = env r in if not (le <= lr) then raise Not_well_typed; sub_exp env e le lr; assign_com env e r; lr | Seq c1 c2 -> let l1 = tc_com_hybrid env c1 cls in let l2 = tc_com_hybrid env c2 cls in let l = meet l1 l2 in sub_com env c1 l1 l; sub_com env c2 l2 l; seq_com env c1 c2 l; l | If e ct cf -> let le = tc_exp env e in let lt = tc_com_hybrid env ct cls in let lf = tc_com_hybrid env cf cls in if not (le <= lt && le <= lf) then raise Not_well_typed; let l = meet lt lf in universal_property_meet le lt lf; sub_exp env e le l; sub_com env ct lt l; sub_com env cf lf l; cond_com env e ct cf l; l | While e c v -> let le = tc_exp env e in let lc = tc_com_hybrid env c cls in if not (le <= lc) then raise Not_well_typed; sub_exp env e le lc; while_com env e c v lc; lc
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.non_informative_t_weakening
val non_informative_t_weakening (g g': env) (g1: env{pairwise_disjoint g g1 g'}) (u: universe) (t: term) (d: non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t
val non_informative_t_weakening (g g': env) (g1: env{pairwise_disjoint g g1 g'}) (u: universe) (t: term) (d: non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t
let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |)
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 92, "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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit ()
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> g': Pulse.Typing.Env.env -> g1: Pulse.Typing.Env.env{Pulse.Typing.Env.pairwise_disjoint g g1 g'} -> u203: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> d: Pulse.Typing.non_informative_t (Pulse.Typing.Env.push_env g g') u203 t -> Pulse.Typing.non_informative_t (Pulse.Typing.Env.push_env (Pulse.Typing.Env.push_env g g1) g') u203 t
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.Env.pairwise_disjoint", "Pulse.Syntax.Base.universe", "Pulse.Syntax.Base.term", "Pulse.Typing.non_informative_t", "Pulse.Typing.Env.push_env", "Pulse.Typing.tot_typing", "Pulse.Typing.non_informative_witness_t", "Prims.Mkdtuple2", "Pulse.RuntimeUtils.magic" ]
[]
false
false
false
false
false
let non_informative_t_weakening (g g': env) (g1: env{pairwise_disjoint g g1 g'}) (u: universe) (t: term) (d: non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t =
let (| w , _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |)
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_encrypt_vec
val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)))
val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)))
let chacha20_encrypt_vec #w len out text key n ctr = push_frame(); let ctx = create_state w in chacha20_init #w ctx key n ctr; chacha20_update #w ctx len out text; pop_frame()
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 218, "start_col": 0, "start_line": 213 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame() noextract val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_last #w ctx len out incr text = push_frame(); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame() noextract val chacha20_update: #w:lanes -> ctx:state w -> len:size_t{v len / (w * 64) <= max_size_t} -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ eq_or_disjoint text out /\ disjoint text ctx /\ disjoint out ctx)) (ensures (fun h0 _ h1 -> modifies (loc ctx |+| loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_update (as_seq h0 ctx) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_update #w ctx len out text = assert_norm (range (v len / v (size w *! 64ul)) U32); let blocks = len /. (size w *! 64ul) in let rem = len %. (size w *! 64ul) in let h0 = ST.get() in map_blocks h0 len (size w *! 64ul) text out (fun h -> Spec.chacha20_encrypt_block (as_seq h0 ctx)) (fun h -> Spec.chacha20_encrypt_last (as_seq h0 ctx)) (fun i -> chacha20_encrypt_block ctx (sub out (i *! (size w *! 64ul)) (size w *! 64ul)) i (sub text (i *! (size w *! 64ul)) (size w *! 64ul))) (fun i -> chacha20_encrypt_last ctx rem (sub out (i *! (size w *! 64ul)) rem) i (sub text (i *! (size w *! 64ul)) rem)) noextract val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)))
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> text: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul -> ctr: Lib.IntTypes.size_t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Chacha20.Vec.chacha20_update", "Hacl.Impl.Chacha20.Vec.chacha20_init", "Hacl.Impl.Chacha20.Core32xN.state", "Hacl.Impl.Chacha20.Core32xN.create_state", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let chacha20_encrypt_vec #w len out text key n ctr =
push_frame (); let ctx = create_state w in chacha20_init #w ctx key n ctr; chacha20_update #w ctx len out text; pop_frame ()
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.size_pos
val size_pos : Type0
let size_pos = x:size_t{v x > 0}
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 32, "start_col": 0, "start_line": 32 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB" ]
[]
false
false
false
true
true
let size_pos =
x: size_t{v x > 0}
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_decrypt_vec
val chacha20_decrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> cipher:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_decrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher)))
val chacha20_decrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> cipher:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_decrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher)))
let chacha20_decrypt_vec #w len out cipher key n ctr = push_frame(); let ctx = create_state w in chacha20_init ctx key n ctr; chacha20_update ctx len out cipher; pop_frame()
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 263, "start_col": 0, "start_line": 258 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame() noextract val chacha20_encrypt_last: #w:lanes -> ctx:state w -> len:size_t{v len < w * 64} -> out:lbuffer uint8 len -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_last #w ctx len out incr text = push_frame(); let plain = create (size w *! size 64) (u8 0) in update_sub plain 0ul len text; chacha20_encrypt_block ctx plain incr plain; copy out (sub plain 0ul len); pop_frame() noextract val chacha20_update: #w:lanes -> ctx:state w -> len:size_t{v len / (w * 64) <= max_size_t} -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ eq_or_disjoint text out /\ disjoint text ctx /\ disjoint out ctx)) (ensures (fun h0 _ h1 -> modifies (loc ctx |+| loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_update (as_seq h0 ctx) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_update #w ctx len out text = assert_norm (range (v len / v (size w *! 64ul)) U32); let blocks = len /. (size w *! 64ul) in let rem = len %. (size w *! 64ul) in let h0 = ST.get() in map_blocks h0 len (size w *! 64ul) text out (fun h -> Spec.chacha20_encrypt_block (as_seq h0 ctx)) (fun h -> Spec.chacha20_encrypt_last (as_seq h0 ctx)) (fun i -> chacha20_encrypt_block ctx (sub out (i *! (size w *! 64ul)) (size w *! 64ul)) i (sub text (i *! (size w *! 64ul)) (size w *! 64ul))) (fun i -> chacha20_encrypt_last ctx rem (sub out (i *! (size w *! 64ul)) rem) i (sub text (i *! (size w *! 64ul)) rem)) noextract val chacha20_encrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text))) [@ Meta.Attribute.inline_ ] let chacha20_encrypt_vec #w len out text key n ctr = push_frame(); let ctx = create_state w in chacha20_init #w ctx key n ctr; chacha20_update #w ctx len out text; pop_frame() inline_for_extraction noextract let chacha20_encrypt_st (w:lanes) = len:size_t -> out:lbuffer uint8 len -> text:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t{v ctr + w <= max_size_t } -> Stack unit (requires fun h -> live h key /\ live h n /\ live h text /\ live h out /\ eq_or_disjoint text out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.Chacha20.chacha20_encrypt_bytes (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text)) noextract val chacha20_encrypt: #w:lanes -> chacha20_encrypt_st w [@ Meta.Attribute.specialize ] let chacha20_encrypt #w len out text key n ctr = let h0 = ST.get () in chacha20_encrypt_vec #w len out text key n ctr; Chacha20Equiv.lemma_chacha20_vec_equiv #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 text) noextract val chacha20_decrypt_vec: #w:lanes -> len:size_t -> out:lbuffer uint8 len -> cipher:lbuffer uint8 len -> key:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr:size_t -> Stack unit (requires (fun h -> live h key /\ live h n /\ live h cipher /\ live h out /\ eq_or_disjoint cipher out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_decrypt_bytes #w (as_seq h0 key) (as_seq h0 n) (v ctr) (as_seq h0 cipher)))
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> cipher: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul -> ctr: Lib.IntTypes.size_t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Chacha20.Vec.chacha20_update", "Hacl.Impl.Chacha20.Vec.chacha20_init", "Hacl.Impl.Chacha20.Core32xN.state", "Hacl.Impl.Chacha20.Core32xN.create_state", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let chacha20_decrypt_vec #w len out cipher key n ctr =
push_frame (); let ctx = create_state w in chacha20_init ctx key n ctr; chacha20_update ctx len out cipher; pop_frame ()
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.non_informative_c_weakening
val non_informative_c_weakening (g g': env) (g1: env{pairwise_disjoint g g1 g'}) (c: comp_st) (d: non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c
val non_informative_c_weakening (g g': env) (g1: env{pairwise_disjoint g g1 g'}) (c: comp_st) (d: non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c
let non_informative_c_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (c:comp_st) (d:non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c = non_informative_t_weakening g g' g1 _ _ d
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 98, "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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit () let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> g': Pulse.Typing.Env.env -> g1: Pulse.Typing.Env.env{Pulse.Typing.Env.pairwise_disjoint g g1 g'} -> c: Pulse.Syntax.Base.comp_st -> d: Pulse.Typing.non_informative_c (Pulse.Typing.Env.push_env g g') c -> Pulse.Typing.non_informative_c (Pulse.Typing.Env.push_env (Pulse.Typing.Env.push_env g g1) g') c
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.Env.pairwise_disjoint", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.non_informative_c", "Pulse.Typing.Env.push_env", "Pulse.Typing.Metatheory.Base.non_informative_t_weakening", "Pulse.Syntax.Base.comp_u", "Pulse.Syntax.Base.comp_res" ]
[]
false
false
false
false
false
let non_informative_c_weakening (g g': env) (g1: env{pairwise_disjoint g g1 g'}) (c: comp_st) (d: non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c =
non_informative_t_weakening g g' g1 _ _ d
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.st_sub_weakening
val st_sub_weakening (g: env) (g': env{disjoint g g'}) (#c1 #c2: comp) (d: st_sub (push_env g g') c1 c2) (g1: env{pairwise_disjoint g g1 g'}) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d)
val st_sub_weakening (g: env) (g': env{disjoint g g'}) (#c1 #c2: comp) (d: st_sub (push_env g g') c1 c2) (g1: env{pairwise_disjoint g g1 g'}) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d)
let rec st_sub_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_sub (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d) = let g'' = push_env (push_env g g1) g' in match d with | STS_Refl _ _ -> STS_Refl _ _ | STS_Trans _ _ _ _ dl dr -> STS_Trans _ _ _ _ (st_sub_weakening g g' dl g1) (st_sub_weakening g g' dr g1) | STS_AtomicInvs _ stc is1 is2 o1 o2 tok -> let tok : prop_validity g'' (tm_inames_subset is1 is2) = prop_validity_token_weakening tok g'' in STS_AtomicInvs g'' stc is1 is2 o1 o2 tok
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 161, "start_col": 0, "start_line": 147 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit () let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (c:comp_st) (d:non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c = non_informative_t_weakening g g' g1 _ _ d let bind_comp_weakening (g:env) (g':env { disjoint g g' }) (#x:var) (#c1 #c2 #c3:comp) (d:bind_comp (push_env g g') x c1 c2 c3) (g1:env { pairwise_disjoint g g1 g' }) : Tot (bind_comp (push_env (push_env g g1) g') x c1 c2 c3) (decreases d) = match d with | Bind_comp _ x c1 c2 _ _ _ -> assume (None? (lookup (push_env g g1) x)); let y = fresh (push_env (push_env g g1) g') in assume (~ (y `Set.mem` (freevars (comp_post c2)))); Bind_comp _ x c1 c2 (RU.magic ()) y (RU.magic ()) let lift_comp_weakening (g:env) (g':env { disjoint g g'}) (#c1 #c2:comp) (d:lift_comp (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d) = match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ c | Lift_Ghost_Neutral _ c non_informative_c -> Lift_Ghost_Neutral _ c (non_informative_c_weakening g g' g1 _ non_informative_c) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ c | Lift_Observability _ obs c -> Lift_Observability _ obs c #push-options "--admit_smt_queries true" let st_equiv_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_equiv (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : st_equiv (push_env (push_env g g1) g') c1 c2 = match d with | ST_VPropEquiv _ c1 c2 x _ _ _ _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); // TODO: the proof for RT.Equiv is not correct here ST_VPropEquiv _ c1 c2 x (RU.magic ()) (RU.magic ()) (RU.magic ()) (FStar.Reflection.Typing.Rel_refl _ _ _) (RU.magic ()) (RU.magic ()) #pop-options // TODO: add precondition that g1 extends g' let prop_validity_token_weakening (#g:env) (#t:term) (token:prop_validity g t) (g1:env) : prop_validity g1 t = admit (); token
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> g': Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint g g'} -> d: Pulse.Typing.st_sub (Pulse.Typing.Env.push_env g g') c1 c2 -> g1: Pulse.Typing.Env.env{Pulse.Typing.Env.pairwise_disjoint g g1 g'} -> Prims.Tot (Pulse.Typing.st_sub (Pulse.Typing.Env.push_env (Pulse.Typing.Env.push_env g g1) g') c1 c2)
Prims.Tot
[ "total", "" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.Env.disjoint", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_sub", "Pulse.Typing.Env.push_env", "Pulse.Typing.Env.pairwise_disjoint", "Pulse.Typing.STS_Refl", "Pulse.Typing.STS_Trans", "Pulse.Typing.Metatheory.Base.st_sub_weakening", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.observability", "Prims.b2t", "Pulse.Typing.sub_observability", "Pulse.Typing.prop_validity", "Pulse.Typing.tm_inames_subset", "Pulse.Typing.STS_AtomicInvs", "Pulse.Typing.Metatheory.Base.prop_validity_token_weakening" ]
[ "recursion" ]
false
false
false
false
false
let rec st_sub_weakening (g: env) (g': env{disjoint g g'}) (#c1 #c2: comp) (d: st_sub (push_env g g') c1 c2) (g1: env{pairwise_disjoint g g1 g'}) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d) =
let g'' = push_env (push_env g g1) g' in match d with | STS_Refl _ _ -> STS_Refl _ _ | STS_Trans _ _ _ _ dl dr -> STS_Trans _ _ _ _ (st_sub_weakening g g' dl g1) (st_sub_weakening g g' dr g1) | STS_AtomicInvs _ stc is1 is2 o1 o2 tok -> let tok:prop_validity g'' (tm_inames_subset is1 is2) = prop_validity_token_weakening tok g'' in STS_AtomicInvs g'' stc is1 is2 o1 o2 tok
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.lift_comp_weakening
val lift_comp_weakening (g: env) (g': env{disjoint g g'}) (#c1 #c2: comp) (d: lift_comp (push_env g g') c1 c2) (g1: env{pairwise_disjoint g g1 g'}) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d)
val lift_comp_weakening (g: env) (g': env{disjoint g g'}) (#c1 #c2: comp) (d: lift_comp (push_env g g') c1 c2) (g1: env{pairwise_disjoint g g1 g'}) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d)
let lift_comp_weakening (g:env) (g':env { disjoint g g'}) (#c1 #c2:comp) (d:lift_comp (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d) = match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ c | Lift_Ghost_Neutral _ c non_informative_c -> Lift_Ghost_Neutral _ c (non_informative_c_weakening g g' g1 _ non_informative_c) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ c | Lift_Observability _ obs c -> Lift_Observability _ obs c
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 60, "end_line": 124, "start_col": 0, "start_line": 113 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit () let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (c:comp_st) (d:non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c = non_informative_t_weakening g g' g1 _ _ d let bind_comp_weakening (g:env) (g':env { disjoint g g' }) (#x:var) (#c1 #c2 #c3:comp) (d:bind_comp (push_env g g') x c1 c2 c3) (g1:env { pairwise_disjoint g g1 g' }) : Tot (bind_comp (push_env (push_env g g1) g') x c1 c2 c3) (decreases d) = match d with | Bind_comp _ x c1 c2 _ _ _ -> assume (None? (lookup (push_env g g1) x)); let y = fresh (push_env (push_env g g1) g') in assume (~ (y `Set.mem` (freevars (comp_post c2)))); Bind_comp _ x c1 c2 (RU.magic ()) y (RU.magic ())
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> g': Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint g g'} -> d: Pulse.Typing.lift_comp (Pulse.Typing.Env.push_env g g') c1 c2 -> g1: Pulse.Typing.Env.env{Pulse.Typing.Env.pairwise_disjoint g g1 g'} -> Prims.Tot (Pulse.Typing.lift_comp (Pulse.Typing.Env.push_env (Pulse.Typing.Env.push_env g g1) g') c1 c2)
Prims.Tot
[ "total", "" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.Env.disjoint", "Pulse.Syntax.Base.comp", "Pulse.Typing.lift_comp", "Pulse.Typing.Env.push_env", "Pulse.Typing.Env.pairwise_disjoint", "Pulse.Syntax.Base.comp_st", "Prims.b2t", "Pulse.Syntax.Base.uu___is_C_STAtomic", "Pulse.Typing.Lift_STAtomic_ST", "Pulse.Syntax.Base.uu___is_C_STGhost", "Pulse.Typing.non_informative_c", "Pulse.Typing.Lift_Ghost_Neutral", "Pulse.Typing.Metatheory.Base.non_informative_c_weakening", "Prims.l_and", "Prims.eq2", "Pulse.Syntax.Base.observability", "Pulse.Syntax.Base.__proj__C_STAtomic__item__obs", "Pulse.Syntax.Base.Neutral", "Pulse.Typing.Lift_Neutral_Ghost", "Pulse.Typing.sub_observability", "Pulse.Typing.Lift_Observability" ]
[]
false
false
false
false
false
let lift_comp_weakening (g: env) (g': env{disjoint g g'}) (#c1 #c2: comp) (d: lift_comp (push_env g g') c1 c2) (g1: env{pairwise_disjoint g g1 g'}) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d) =
match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ c | Lift_Ghost_Neutral _ c non_informative_c -> Lift_Ghost_Neutral _ c (non_informative_c_weakening g g' g1 _ non_informative_c) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ c | Lift_Observability _ obs c -> Lift_Observability _ obs c
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.coerce_eq
val coerce_eq: #a: Type -> #b: Type -> x: a -> squash (a == b) -> y: b{y == x}
val coerce_eq: #a: Type -> #b: Type -> x: a -> squash (a == b) -> y: b{y == x}
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b { y == x } = x
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 73, "end_line": 561, "start_col": 0, "start_line": 561 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit () let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (c:comp_st) (d:non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c = non_informative_t_weakening g g' g1 _ _ d let bind_comp_weakening (g:env) (g':env { disjoint g g' }) (#x:var) (#c1 #c2 #c3:comp) (d:bind_comp (push_env g g') x c1 c2 c3) (g1:env { pairwise_disjoint g g1 g' }) : Tot (bind_comp (push_env (push_env g g1) g') x c1 c2 c3) (decreases d) = match d with | Bind_comp _ x c1 c2 _ _ _ -> assume (None? (lookup (push_env g g1) x)); let y = fresh (push_env (push_env g g1) g') in assume (~ (y `Set.mem` (freevars (comp_post c2)))); Bind_comp _ x c1 c2 (RU.magic ()) y (RU.magic ()) let lift_comp_weakening (g:env) (g':env { disjoint g g'}) (#c1 #c2:comp) (d:lift_comp (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d) = match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ c | Lift_Ghost_Neutral _ c non_informative_c -> Lift_Ghost_Neutral _ c (non_informative_c_weakening g g' g1 _ non_informative_c) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ c | Lift_Observability _ obs c -> Lift_Observability _ obs c #push-options "--admit_smt_queries true" let st_equiv_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_equiv (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : st_equiv (push_env (push_env g g1) g') c1 c2 = match d with | ST_VPropEquiv _ c1 c2 x _ _ _ _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); // TODO: the proof for RT.Equiv is not correct here ST_VPropEquiv _ c1 c2 x (RU.magic ()) (RU.magic ()) (RU.magic ()) (FStar.Reflection.Typing.Rel_refl _ _ _) (RU.magic ()) (RU.magic ()) #pop-options // TODO: add precondition that g1 extends g' let prop_validity_token_weakening (#g:env) (#t:term) (token:prop_validity g t) (g1:env) : prop_validity g1 t = admit (); token let rec st_sub_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_sub (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d) = let g'' = push_env (push_env g g1) g' in match d with | STS_Refl _ _ -> STS_Refl _ _ | STS_Trans _ _ _ _ dl dr -> STS_Trans _ _ _ _ (st_sub_weakening g g' dl g1) (st_sub_weakening g g' dr g1) | STS_AtomicInvs _ stc is1 is2 o1 o2 tok -> let tok : prop_validity g'' (tm_inames_subset is1 is2) = prop_validity_token_weakening tok g'' in STS_AtomicInvs g'' stc is1 is2 o1 o2 tok let st_comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#s:st_comp) (d:st_comp_typing (push_env g g') s) (g1:env { pairwise_disjoint g g1 g' }) : st_comp_typing (push_env (push_env g g1) g') s = match d with | STC _ st x _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); STC _ st x (RU.magic ()) (RU.magic ()) (RU.magic ()) let comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#c:comp) (#u:universe) (d:comp_typing (push_env g g') c u) (g1:env { pairwise_disjoint g g1 g' }) : comp_typing (push_env (push_env g g1) g') c u = match d with | CT_Tot _ t u _ -> CT_Tot _ t u (RU.magic ()) | CT_ST _ _ d -> CT_ST _ _ (st_comp_typing_weakening g g' d g1) | CT_STAtomic _ inames obs _ _ d -> CT_STAtomic _ inames obs _ (RU.magic ()) (st_comp_typing_weakening g g' d g1) | CT_STGhost _ _ d -> CT_STGhost _ _ (st_comp_typing_weakening g g' d g1) #push-options "--split_queries no --z3rlimit_factor 8 --fuel 1 --ifuel 1" let rec st_typing_weakening g g' t c d g1 : Tot (st_typing (push_env (push_env g g1) g') t c) (decreases d) = match d with | T_Abs g x q b u body c b_typing body_typing -> // T_Abs is used only at the top, should not come up assume false; let x = fresh (push_env (push_env g g1) g') in T_Abs g x q b u body c (RU.magic #(tot_typing _ _ _) ()) (st_typing_weakening g g' body c body_typing g1) | T_STApp _ head ty q res arg _ _ -> T_STApp _ head ty q res arg (RU.magic #(tot_typing _ _ _) ()) (RU.magic #(tot_typing _ _ _) ()) | T_STGhostApp _ head ty q res arg _ _ _ _ -> // candidate for renaming let x = fresh (push_env (push_env g g1) g') in assume (~ (x `Set.mem` freevars_comp res)); T_STGhostApp _ head ty q res arg x (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_Return _ c use_eq u t e post x_old _ _ _ -> let x = fresh (push_env (push_env g g1) g') in assume (~ (x `Set.mem` freevars post)); // x is only used to open and then close assume (comp_return c use_eq u t e post x_old == comp_return c use_eq u t e post x); T_Return _ c use_eq u t e post x (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_Lift _ e c1 c2 d_c1 d_lift -> T_Lift _ e c1 c2 (st_typing_weakening g g' e c1 d_c1 g1) (lift_comp_weakening g g' d_lift g1) | T_Bind _ e1 e2 c1 c2 b x c d_e1 _ d_e2 d_bc -> let d_e1 : st_typing (push_env (push_env g g1) g') e1 c1 = st_typing_weakening g g' e1 c1 d_e1 g1 in // // When we call it, g' will actually be empty // And they way bind checker invokes the lemma, we also know x is not in g1 // But we must fix it cleanly // Perhaps typing rules should take a thunk, fun (x:var) ... // assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_e2 : st_typing (push_binding (push_env g g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in assert (equal (push_binding (push_env g g') x ppname_default (comp_res c1)) (push_env g (push_binding g' x ppname_default (comp_res c1)))); let d_e2 : st_typing (push_env g (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = st_typing_weakening g (push_binding g' x ppname_default (comp_res c1)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_bc = bind_comp_weakening g g' d_bc g1 in T_Bind _ e1 e2 c1 c2 b x c d_e1 (RU.magic ()) d_e2 d_bc | T_BindFn _ e1 e2 c1 c2 b x d_e1 u _ d_e2 c2_typing -> let d_e1 : st_typing (push_env (push_env g g1) g') e1 c1 = st_typing_weakening g g' e1 c1 d_e1 g1 in // // When we call it, g' will actually be empty // And they way bind checker invokes the lemma, we also know x is not in g1 // But we must fix it cleanly // Perhaps typing rules should take a thunk, fun (x:var) ... // assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_e2 : st_typing (push_binding (push_env g g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in assert (equal (push_binding (push_env g g') x ppname_default (comp_res c1)) (push_env g (push_binding g' x ppname_default (comp_res c1)))); let d_e2 : st_typing (push_env g (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = st_typing_weakening g (push_binding g' x ppname_default (comp_res c1)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let c2_typing = comp_typing_weakening g g' c2_typing g1 in T_BindFn _ e1 e2 c1 c2 b x d_e1 u (RU.magic #(tot_typing _ _ _) ()) d_e2 c2_typing | T_If _ b e1 e2 c hyp _ d_e1 d_e2 _ -> assume (~ (hyp `Set.mem` dom g')); assume (~ (hyp `Set.mem` dom g1)); let d_e1 : st_typing (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c = d_e1 in assert (equal (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)))); let d_e1 : st_typing (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) e1 c = d_e1 in let d_e1 : st_typing (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) e1 c = st_typing_weakening g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) _ _ d_e1 g1 in assert (equal (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))); let d_e1 : st_typing (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c = d_e1 in let d_e2 : st_typing (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c = d_e2 in assert (equal (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)))); let d_e2 : st_typing (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) e2 c = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) e2 c = st_typing_weakening g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c = d_e2 in T_If _ b e1 e2 c hyp (RU.magic ()) d_e1 d_e2 (RU.magic ()) | T_Match _ sc_u sc_ty sc d_sc_ty d_sc c c_typing brs d_brs d_pats_complete -> admit(); T_Match (push_env (push_env g g1) g') sc_u sc_ty sc (tot_typing_weakening g g' _ _ d_sc_ty g1) (tot_typing_weakening g g' _ _ d_sc g1) c c_typing brs d_brs d_pats_complete | T_Frame _ e c frame _ d_e -> T_Frame _ e c frame (RU.magic ()) (st_typing_weakening g g' e c d_e g1) | T_Equiv _ e c c' d_e d_eq -> T_Equiv _ e c c' (st_typing_weakening g g' e c d_e g1) (st_equiv_weakening g g' d_eq g1) | T_Sub _ e c c' d_e d_sub -> T_Sub _ e c c' (st_typing_weakening g g' e c d_e g1) (st_sub_weakening g g' d_sub g1) | T_IntroPure _ p _ token -> T_IntroPure _ p (RU.magic ()) (prop_validity_token_weakening token _) | T_ElimExists _ u t p x _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); T_ElimExists _ u t p x (RU.magic ()) (RU.magic ()) | T_IntroExists _ u b p e _ _ _ -> T_IntroExists _ u b p e (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_While _ inv cond body _ cond_typing body_typing -> T_While _ inv cond body (RU.magic ()) (st_typing_weakening g g' cond (comp_while_cond ppname_default inv) cond_typing g1) (st_typing_weakening g g' body (comp_while_body ppname_default inv) body_typing g1) | T_Par _ eL cL eR cR x cL_typing cR_typing eL_typing eR_typing -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); T_Par _ eL cL eR cR x (comp_typing_weakening g g' cL_typing g1) (comp_typing_weakening g g' cR_typing g1) (st_typing_weakening g g' eL cL eL_typing g1) (st_typing_weakening g g' eR cR eR_typing g1) | T_WithLocal _ ppname init body init_t c x _ _ d_c d_body -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_body : st_typing (push_binding (push_env g g') x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in assert (equal (push_binding (push_env g g') x ppname_default (mk_ref init_t)) (push_env g (push_binding g' x ppname_default (mk_ref init_t)))); let d_body : st_typing (push_env g (push_binding g' x ppname_default (mk_ref init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in let d_body : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (mk_ref init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = st_typing_weakening g (push_binding g' x ppname_default (mk_ref init_t)) _ _ d_body g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (mk_ref init_t))) (push_binding (push_env (push_env g g1) g') x ppname_default (mk_ref init_t))); let d_body : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in T_WithLocal _ ppname init body init_t c x (RU.magic ()) (RU.magic ()) (comp_typing_weakening g g' d_c g1) d_body | T_WithLocalArray _ ppname init len body init_t c x _ _ _ d_c d_body -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_body : st_typing (push_binding (push_env g g') x ppname_default (mk_array init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in assert (equal (push_binding (push_env g g') x ppname_default (mk_array init_t)) (push_env g (push_binding g' x ppname_default (mk_array init_t)))); let d_body : st_typing (push_env g (push_binding g' x ppname_default (mk_array init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in let d_body : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (mk_array init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = st_typing_weakening g (push_binding g' x ppname_default (mk_array init_t)) _ _ d_body g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (mk_array init_t))) (push_binding (push_env (push_env g g1) g') x ppname_default (mk_array init_t))); let d_body : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (mk_array init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in T_WithLocalArray _ ppname init len body init_t c x (RU.magic ()) (RU.magic ()) (RU.magic ()) (comp_typing_weakening g g' d_c g1) d_body | T_Rewrite _ p q _ _ -> T_Rewrite _ p q (RU.magic ()) (RU.magic ()) | T_Admit _ s c d_s -> T_Admit _ s c (st_comp_typing_weakening g g' d_s g1) | T_Unreachable _ s c d_s tok -> T_Unreachable _ s c (st_comp_typing_weakening g g' d_s g1) (RU.magic())//weaken tok | T_WithInv _ _ _ p_typing inv_typing _ _ body_typing tok -> T_WithInv _ _ _ (tot_typing_weakening g g' _ _ p_typing g1) (tot_typing_weakening g g' _ _ inv_typing g1) _ _ (st_typing_weakening g g' _ _ body_typing g1) (prop_validity_token_weakening tok _) #pop-options #push-options "--admit_smt_queries true" let non_informative_t_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (u:universe) (t1:term) (d:non_informative_t (push_env g (push_env (singleton_env (fstar_env g) x t) g')) u t1) : non_informative_t (push_env g (subst_env g' (nt x e))) u (subst_term t1 (nt x e)) = let ss = nt x e in let (| w, _ |) = d in (| subst_term w ss, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (c:comp) (d:non_informative_c (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c) : non_informative_c (push_env g (subst_env g' (nt x e))) (subst_comp c (nt x e)) = non_informative_t_subst g x t g' e_typing _ _ d let lift_comp_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (#c1 #c2:comp) (d:lift_comp (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c1 c2) : lift_comp (push_env g (subst_env g' (nt x e))) (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e)) = let ss = nt x e in match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ (subst_comp c ss) | Lift_Ghost_Neutral _ c d_non_informative -> Lift_Ghost_Neutral _ (subst_comp c ss) (non_informative_c_subst g x t g' e_typing _ d_non_informative) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ (subst_comp c ss) | Lift_Observability _ c o -> Lift_Observability _ (subst_comp c ss) o let bind_comp_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (#y:var) (#c1 #c2 #c3:comp) (d:bind_comp (push_env g (push_env (singleton_env (fstar_env g) x t) g')) y c1 c2 c3) : bind_comp (push_env g (subst_env g' (nt x e))) y (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e)) (subst_comp c3 (nt x e)) = let ss = nt x e in match d with | Bind_comp _ y c1 c2 _ z _ -> Bind_comp _ y (subst_comp c1 ss) (subst_comp c2 ss) (RU.magic ()) z (RU.magic ()) let st_equiv_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (#c1 #c2:comp) (d:st_equiv (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c1 c2) : st_equiv (push_env g (subst_env g' (nt x e))) (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e)) = match d with | ST_VPropEquiv _ c1 c2 y _ _ _ _ _ _ -> ST_VPropEquiv _ (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e)) y (RU.magic ()) (RU.magic ()) (RU.magic ()) (RT.Rel_refl _ _ _) // TODO: incorrect proof (RU.magic ()) (RU.magic ()) let st_comp_typing_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (#s:st_comp) (d:st_comp_typing (push_env g (push_env (singleton_env (fstar_env g) x t) g')) s) : st_comp_typing (push_env g (subst_env g' (nt x e))) (subst_st_comp s (nt x e)) = match d with | STC _ s y _ _ _ -> STC _ (subst_st_comp s (nt x e)) y (RU.magic ()) (RU.magic ()) (RU.magic ()) let comp_typing_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (#c:comp) (#u:universe) (d:comp_typing (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c u) : comp_typing (push_env g (subst_env g' (nt x e))) (subst_comp c (nt x e)) u = match d with | CT_Tot _ t u _ -> CT_Tot _ (subst_term t (nt x e)) u (RU.magic ()) | CT_ST _ s d_s -> CT_ST _ (subst_st_comp s (nt x e)) (st_comp_typing_subst g x t g' e_typing d_s) | CT_STAtomic _ inames obs s _ d_s -> CT_STAtomic _ inames obs (subst_st_comp s (nt x e)) (RU.magic ()) (st_comp_typing_subst g x t g' e_typing d_s) | CT_STGhost _ _ d_s -> CT_STGhost _ _ (st_comp_typing_subst g x t g' e_typing d_s)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> _: Prims.squash (a == b) -> y: b{y == x}
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "Prims.eq2" ]
[]
false
false
false
false
false
let coerce_eq (#a: Type) (#b: Type) (x: a) (_: squash (a == b)) : y: b{y == x} =
x
false
HyE.PlainPKE.fst
HyE.PlainPKE.repr
val repr: p:t{not conf} -> Tot r
val repr: p:t{not conf} -> Tot r
let repr t = HyE.AE.leak t
{ "file_name": "examples/crypto/HyE.PlainPKE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 26, "start_col": 0, "start_line": 26 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module HyE.PlainPKE open HyE.RSA open HyE.Ideal type t = HyE.AE.key // This should be abstract type r = HyE.RSA.plain (* two pure functions, never called when ideal *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "HyE.RSA.fst.checked", "HyE.Ideal.fsti.checked", "HyE.AE.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "HyE.PlainPKE.fst" }
[ { "abbrev": false, "full_module": "HyE.Ideal", "short_module": null }, { "abbrev": false, "full_module": "HyE.RSA", "short_module": null }, { "abbrev": false, "full_module": "HyE", "short_module": null }, { "abbrev": false, "full_module": "HyE", "short_module": null }, { "abbrev": 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: HyE.PlainPKE.t{Prims.op_Negation HyE.Ideal.conf} -> HyE.PlainPKE.r
Prims.Tot
[ "total" ]
[]
[ "HyE.PlainPKE.t", "Prims.b2t", "Prims.op_Negation", "HyE.Ideal.conf", "HyE.AE.leak", "HyE.PlainPKE.r" ]
[]
false
false
false
false
false
let repr t =
HyE.AE.leak t
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.comp_typing_weakening
val comp_typing_weakening (g: env) (g': env{disjoint g g'}) (#c: comp) (#u: universe) (d: comp_typing (push_env g g') c u) (g1: env{pairwise_disjoint g g1 g'}) : comp_typing (push_env (push_env g g1) g') c u
val comp_typing_weakening (g: env) (g': env{disjoint g g'}) (#c: comp) (#u: universe) (d: comp_typing (push_env g g') c u) (g1: env{pairwise_disjoint g g1 g'}) : comp_typing (push_env (push_env g g1) g') c u
let comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#c:comp) (#u:universe) (d:comp_typing (push_env g g') c u) (g1:env { pairwise_disjoint g g1 g' }) : comp_typing (push_env (push_env g g1) g') c u = match d with | CT_Tot _ t u _ -> CT_Tot _ t u (RU.magic ()) | CT_ST _ _ d -> CT_ST _ _ (st_comp_typing_weakening g g' d g1) | CT_STAtomic _ inames obs _ _ d -> CT_STAtomic _ inames obs _ (RU.magic ()) (st_comp_typing_weakening g g' d g1) | CT_STGhost _ _ d -> CT_STGhost _ _ (st_comp_typing_weakening g g' d g1)
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 183, "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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit () let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (c:comp_st) (d:non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c = non_informative_t_weakening g g' g1 _ _ d let bind_comp_weakening (g:env) (g':env { disjoint g g' }) (#x:var) (#c1 #c2 #c3:comp) (d:bind_comp (push_env g g') x c1 c2 c3) (g1:env { pairwise_disjoint g g1 g' }) : Tot (bind_comp (push_env (push_env g g1) g') x c1 c2 c3) (decreases d) = match d with | Bind_comp _ x c1 c2 _ _ _ -> assume (None? (lookup (push_env g g1) x)); let y = fresh (push_env (push_env g g1) g') in assume (~ (y `Set.mem` (freevars (comp_post c2)))); Bind_comp _ x c1 c2 (RU.magic ()) y (RU.magic ()) let lift_comp_weakening (g:env) (g':env { disjoint g g'}) (#c1 #c2:comp) (d:lift_comp (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d) = match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ c | Lift_Ghost_Neutral _ c non_informative_c -> Lift_Ghost_Neutral _ c (non_informative_c_weakening g g' g1 _ non_informative_c) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ c | Lift_Observability _ obs c -> Lift_Observability _ obs c #push-options "--admit_smt_queries true" let st_equiv_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_equiv (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : st_equiv (push_env (push_env g g1) g') c1 c2 = match d with | ST_VPropEquiv _ c1 c2 x _ _ _ _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); // TODO: the proof for RT.Equiv is not correct here ST_VPropEquiv _ c1 c2 x (RU.magic ()) (RU.magic ()) (RU.magic ()) (FStar.Reflection.Typing.Rel_refl _ _ _) (RU.magic ()) (RU.magic ()) #pop-options // TODO: add precondition that g1 extends g' let prop_validity_token_weakening (#g:env) (#t:term) (token:prop_validity g t) (g1:env) : prop_validity g1 t = admit (); token let rec st_sub_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_sub (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d) = let g'' = push_env (push_env g g1) g' in match d with | STS_Refl _ _ -> STS_Refl _ _ | STS_Trans _ _ _ _ dl dr -> STS_Trans _ _ _ _ (st_sub_weakening g g' dl g1) (st_sub_weakening g g' dr g1) | STS_AtomicInvs _ stc is1 is2 o1 o2 tok -> let tok : prop_validity g'' (tm_inames_subset is1 is2) = prop_validity_token_weakening tok g'' in STS_AtomicInvs g'' stc is1 is2 o1 o2 tok let st_comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#s:st_comp) (d:st_comp_typing (push_env g g') s) (g1:env { pairwise_disjoint g g1 g' }) : st_comp_typing (push_env (push_env g g1) g') s = match d with | STC _ st x _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); STC _ st x (RU.magic ()) (RU.magic ()) (RU.magic ())
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> g': Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint g g'} -> d: Pulse.Typing.comp_typing (Pulse.Typing.Env.push_env g g') c u295 -> g1: Pulse.Typing.Env.env{Pulse.Typing.Env.pairwise_disjoint g g1 g'} -> Pulse.Typing.comp_typing (Pulse.Typing.Env.push_env (Pulse.Typing.Env.push_env g g1) g') c u295
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.Env.disjoint", "Pulse.Syntax.Base.comp", "Pulse.Syntax.Base.universe", "Pulse.Typing.comp_typing", "Pulse.Typing.Env.push_env", "Pulse.Typing.Env.pairwise_disjoint", "Pulse.Syntax.Base.term", "Pulse.Typing.universe_of", "Pulse.Typing.CT_Tot", "Pulse.RuntimeUtils.magic", "Pulse.Syntax.Base.st_comp", "Pulse.Typing.st_comp_typing", "Pulse.Typing.CT_ST", "Pulse.Typing.Metatheory.Base.st_comp_typing_weakening", "Pulse.Syntax.Base.observability", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.tm_inames", "Pulse.Typing.CT_STAtomic", "Pulse.Typing.CT_STGhost" ]
[]
false
false
false
false
false
let comp_typing_weakening (g: env) (g': env{disjoint g g'}) (#c: comp) (#u: universe) (d: comp_typing (push_env g g') c u) (g1: env{pairwise_disjoint g g1 g'}) : comp_typing (push_env (push_env g g1) g') c u =
match d with | CT_Tot _ t u _ -> CT_Tot _ t u (RU.magic ()) | CT_ST _ _ d -> CT_ST _ _ (st_comp_typing_weakening g g' d g1) | CT_STAtomic _ inames obs _ _ d -> CT_STAtomic _ inames obs _ (RU.magic ()) (st_comp_typing_weakening g g' d g1) | CT_STGhost _ _ d -> CT_STGhost _ _ (st_comp_typing_weakening g g' d g1)
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.non_informative_t_subst
val non_informative_t_subst (g: env) (x: var) (t: typ) (g': env{pairwise_disjoint g (singleton_env (fstar_env g) x t) g'}) (#e: term) (e_typing: tot_typing g e t) (u: universe) (t1: term) (d: non_informative_t (push_env g (push_env (singleton_env (fstar_env g) x t) g')) u t1) : non_informative_t (push_env g (subst_env g' (nt x e))) u (subst_term t1 (nt x e))
val non_informative_t_subst (g: env) (x: var) (t: typ) (g': env{pairwise_disjoint g (singleton_env (fstar_env g) x t) g'}) (#e: term) (e_typing: tot_typing g e t) (u: universe) (t1: term) (d: non_informative_t (push_env g (push_env (singleton_env (fstar_env g) x t) g')) u t1) : non_informative_t (push_env g (subst_env g' (nt x e))) u (subst_term t1 (nt x e))
let non_informative_t_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (u:universe) (t1:term) (d:non_informative_t (push_env g (push_env (singleton_env (fstar_env g) x t) g')) u t1) : non_informative_t (push_env g (subst_env g' (nt x e))) u (subst_term t1 (nt x e)) = let ss = nt x e in let (| w, _ |) = d in (| subst_term w ss, RU.magic #(tot_typing _ _ _) () |)
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 450, "start_col": 0, "start_line": 439 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit () let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (c:comp_st) (d:non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c = non_informative_t_weakening g g' g1 _ _ d let bind_comp_weakening (g:env) (g':env { disjoint g g' }) (#x:var) (#c1 #c2 #c3:comp) (d:bind_comp (push_env g g') x c1 c2 c3) (g1:env { pairwise_disjoint g g1 g' }) : Tot (bind_comp (push_env (push_env g g1) g') x c1 c2 c3) (decreases d) = match d with | Bind_comp _ x c1 c2 _ _ _ -> assume (None? (lookup (push_env g g1) x)); let y = fresh (push_env (push_env g g1) g') in assume (~ (y `Set.mem` (freevars (comp_post c2)))); Bind_comp _ x c1 c2 (RU.magic ()) y (RU.magic ()) let lift_comp_weakening (g:env) (g':env { disjoint g g'}) (#c1 #c2:comp) (d:lift_comp (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d) = match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ c | Lift_Ghost_Neutral _ c non_informative_c -> Lift_Ghost_Neutral _ c (non_informative_c_weakening g g' g1 _ non_informative_c) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ c | Lift_Observability _ obs c -> Lift_Observability _ obs c #push-options "--admit_smt_queries true" let st_equiv_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_equiv (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : st_equiv (push_env (push_env g g1) g') c1 c2 = match d with | ST_VPropEquiv _ c1 c2 x _ _ _ _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); // TODO: the proof for RT.Equiv is not correct here ST_VPropEquiv _ c1 c2 x (RU.magic ()) (RU.magic ()) (RU.magic ()) (FStar.Reflection.Typing.Rel_refl _ _ _) (RU.magic ()) (RU.magic ()) #pop-options // TODO: add precondition that g1 extends g' let prop_validity_token_weakening (#g:env) (#t:term) (token:prop_validity g t) (g1:env) : prop_validity g1 t = admit (); token let rec st_sub_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_sub (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d) = let g'' = push_env (push_env g g1) g' in match d with | STS_Refl _ _ -> STS_Refl _ _ | STS_Trans _ _ _ _ dl dr -> STS_Trans _ _ _ _ (st_sub_weakening g g' dl g1) (st_sub_weakening g g' dr g1) | STS_AtomicInvs _ stc is1 is2 o1 o2 tok -> let tok : prop_validity g'' (tm_inames_subset is1 is2) = prop_validity_token_weakening tok g'' in STS_AtomicInvs g'' stc is1 is2 o1 o2 tok let st_comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#s:st_comp) (d:st_comp_typing (push_env g g') s) (g1:env { pairwise_disjoint g g1 g' }) : st_comp_typing (push_env (push_env g g1) g') s = match d with | STC _ st x _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); STC _ st x (RU.magic ()) (RU.magic ()) (RU.magic ()) let comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#c:comp) (#u:universe) (d:comp_typing (push_env g g') c u) (g1:env { pairwise_disjoint g g1 g' }) : comp_typing (push_env (push_env g g1) g') c u = match d with | CT_Tot _ t u _ -> CT_Tot _ t u (RU.magic ()) | CT_ST _ _ d -> CT_ST _ _ (st_comp_typing_weakening g g' d g1) | CT_STAtomic _ inames obs _ _ d -> CT_STAtomic _ inames obs _ (RU.magic ()) (st_comp_typing_weakening g g' d g1) | CT_STGhost _ _ d -> CT_STGhost _ _ (st_comp_typing_weakening g g' d g1) #push-options "--split_queries no --z3rlimit_factor 8 --fuel 1 --ifuel 1" let rec st_typing_weakening g g' t c d g1 : Tot (st_typing (push_env (push_env g g1) g') t c) (decreases d) = match d with | T_Abs g x q b u body c b_typing body_typing -> // T_Abs is used only at the top, should not come up assume false; let x = fresh (push_env (push_env g g1) g') in T_Abs g x q b u body c (RU.magic #(tot_typing _ _ _) ()) (st_typing_weakening g g' body c body_typing g1) | T_STApp _ head ty q res arg _ _ -> T_STApp _ head ty q res arg (RU.magic #(tot_typing _ _ _) ()) (RU.magic #(tot_typing _ _ _) ()) | T_STGhostApp _ head ty q res arg _ _ _ _ -> // candidate for renaming let x = fresh (push_env (push_env g g1) g') in assume (~ (x `Set.mem` freevars_comp res)); T_STGhostApp _ head ty q res arg x (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_Return _ c use_eq u t e post x_old _ _ _ -> let x = fresh (push_env (push_env g g1) g') in assume (~ (x `Set.mem` freevars post)); // x is only used to open and then close assume (comp_return c use_eq u t e post x_old == comp_return c use_eq u t e post x); T_Return _ c use_eq u t e post x (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_Lift _ e c1 c2 d_c1 d_lift -> T_Lift _ e c1 c2 (st_typing_weakening g g' e c1 d_c1 g1) (lift_comp_weakening g g' d_lift g1) | T_Bind _ e1 e2 c1 c2 b x c d_e1 _ d_e2 d_bc -> let d_e1 : st_typing (push_env (push_env g g1) g') e1 c1 = st_typing_weakening g g' e1 c1 d_e1 g1 in // // When we call it, g' will actually be empty // And they way bind checker invokes the lemma, we also know x is not in g1 // But we must fix it cleanly // Perhaps typing rules should take a thunk, fun (x:var) ... // assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_e2 : st_typing (push_binding (push_env g g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in assert (equal (push_binding (push_env g g') x ppname_default (comp_res c1)) (push_env g (push_binding g' x ppname_default (comp_res c1)))); let d_e2 : st_typing (push_env g (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = st_typing_weakening g (push_binding g' x ppname_default (comp_res c1)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_bc = bind_comp_weakening g g' d_bc g1 in T_Bind _ e1 e2 c1 c2 b x c d_e1 (RU.magic ()) d_e2 d_bc | T_BindFn _ e1 e2 c1 c2 b x d_e1 u _ d_e2 c2_typing -> let d_e1 : st_typing (push_env (push_env g g1) g') e1 c1 = st_typing_weakening g g' e1 c1 d_e1 g1 in // // When we call it, g' will actually be empty // And they way bind checker invokes the lemma, we also know x is not in g1 // But we must fix it cleanly // Perhaps typing rules should take a thunk, fun (x:var) ... // assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_e2 : st_typing (push_binding (push_env g g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in assert (equal (push_binding (push_env g g') x ppname_default (comp_res c1)) (push_env g (push_binding g' x ppname_default (comp_res c1)))); let d_e2 : st_typing (push_env g (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = st_typing_weakening g (push_binding g' x ppname_default (comp_res c1)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let c2_typing = comp_typing_weakening g g' c2_typing g1 in T_BindFn _ e1 e2 c1 c2 b x d_e1 u (RU.magic #(tot_typing _ _ _) ()) d_e2 c2_typing | T_If _ b e1 e2 c hyp _ d_e1 d_e2 _ -> assume (~ (hyp `Set.mem` dom g')); assume (~ (hyp `Set.mem` dom g1)); let d_e1 : st_typing (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c = d_e1 in assert (equal (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)))); let d_e1 : st_typing (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) e1 c = d_e1 in let d_e1 : st_typing (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) e1 c = st_typing_weakening g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) _ _ d_e1 g1 in assert (equal (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))); let d_e1 : st_typing (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c = d_e1 in let d_e2 : st_typing (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c = d_e2 in assert (equal (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)))); let d_e2 : st_typing (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) e2 c = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) e2 c = st_typing_weakening g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c = d_e2 in T_If _ b e1 e2 c hyp (RU.magic ()) d_e1 d_e2 (RU.magic ()) | T_Match _ sc_u sc_ty sc d_sc_ty d_sc c c_typing brs d_brs d_pats_complete -> admit(); T_Match (push_env (push_env g g1) g') sc_u sc_ty sc (tot_typing_weakening g g' _ _ d_sc_ty g1) (tot_typing_weakening g g' _ _ d_sc g1) c c_typing brs d_brs d_pats_complete | T_Frame _ e c frame _ d_e -> T_Frame _ e c frame (RU.magic ()) (st_typing_weakening g g' e c d_e g1) | T_Equiv _ e c c' d_e d_eq -> T_Equiv _ e c c' (st_typing_weakening g g' e c d_e g1) (st_equiv_weakening g g' d_eq g1) | T_Sub _ e c c' d_e d_sub -> T_Sub _ e c c' (st_typing_weakening g g' e c d_e g1) (st_sub_weakening g g' d_sub g1) | T_IntroPure _ p _ token -> T_IntroPure _ p (RU.magic ()) (prop_validity_token_weakening token _) | T_ElimExists _ u t p x _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); T_ElimExists _ u t p x (RU.magic ()) (RU.magic ()) | T_IntroExists _ u b p e _ _ _ -> T_IntroExists _ u b p e (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_While _ inv cond body _ cond_typing body_typing -> T_While _ inv cond body (RU.magic ()) (st_typing_weakening g g' cond (comp_while_cond ppname_default inv) cond_typing g1) (st_typing_weakening g g' body (comp_while_body ppname_default inv) body_typing g1) | T_Par _ eL cL eR cR x cL_typing cR_typing eL_typing eR_typing -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); T_Par _ eL cL eR cR x (comp_typing_weakening g g' cL_typing g1) (comp_typing_weakening g g' cR_typing g1) (st_typing_weakening g g' eL cL eL_typing g1) (st_typing_weakening g g' eR cR eR_typing g1) | T_WithLocal _ ppname init body init_t c x _ _ d_c d_body -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_body : st_typing (push_binding (push_env g g') x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in assert (equal (push_binding (push_env g g') x ppname_default (mk_ref init_t)) (push_env g (push_binding g' x ppname_default (mk_ref init_t)))); let d_body : st_typing (push_env g (push_binding g' x ppname_default (mk_ref init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in let d_body : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (mk_ref init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = st_typing_weakening g (push_binding g' x ppname_default (mk_ref init_t)) _ _ d_body g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (mk_ref init_t))) (push_binding (push_env (push_env g g1) g') x ppname_default (mk_ref init_t))); let d_body : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in T_WithLocal _ ppname init body init_t c x (RU.magic ()) (RU.magic ()) (comp_typing_weakening g g' d_c g1) d_body | T_WithLocalArray _ ppname init len body init_t c x _ _ _ d_c d_body -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_body : st_typing (push_binding (push_env g g') x ppname_default (mk_array init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in assert (equal (push_binding (push_env g g') x ppname_default (mk_array init_t)) (push_env g (push_binding g' x ppname_default (mk_array init_t)))); let d_body : st_typing (push_env g (push_binding g' x ppname_default (mk_array init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in let d_body : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (mk_array init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = st_typing_weakening g (push_binding g' x ppname_default (mk_array init_t)) _ _ d_body g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (mk_array init_t))) (push_binding (push_env (push_env g g1) g') x ppname_default (mk_array init_t))); let d_body : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (mk_array init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in T_WithLocalArray _ ppname init len body init_t c x (RU.magic ()) (RU.magic ()) (RU.magic ()) (comp_typing_weakening g g' d_c g1) d_body | T_Rewrite _ p q _ _ -> T_Rewrite _ p q (RU.magic ()) (RU.magic ()) | T_Admit _ s c d_s -> T_Admit _ s c (st_comp_typing_weakening g g' d_s g1) | T_Unreachable _ s c d_s tok -> T_Unreachable _ s c (st_comp_typing_weakening g g' d_s g1) (RU.magic())//weaken tok | T_WithInv _ _ _ p_typing inv_typing _ _ body_typing tok -> T_WithInv _ _ _ (tot_typing_weakening g g' _ _ p_typing g1) (tot_typing_weakening g g' _ _ inv_typing g1) _ _ (st_typing_weakening g g' _ _ body_typing g1) (prop_validity_token_weakening tok _) #pop-options
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> x: Pulse.Syntax.Base.var -> t: Pulse.Syntax.Base.typ -> g': Pulse.Typing.Env.env { Pulse.Typing.Env.pairwise_disjoint g (Pulse.Typing.Env.singleton_env (Pulse.Typing.Env.fstar_env g) x t) g' } -> e_typing: Pulse.Typing.tot_typing g e t -> u352: Pulse.Syntax.Base.universe -> t1: Pulse.Syntax.Base.term -> d: Pulse.Typing.non_informative_t (Pulse.Typing.Env.push_env g (Pulse.Typing.Env.push_env (Pulse.Typing.Env.singleton_env (Pulse.Typing.Env.fstar_env g ) x t) g')) u352 t1 -> Pulse.Typing.non_informative_t (Pulse.Typing.Env.push_env g (Pulse.Typing.Env.subst_env g' (Pulse.Typing.Metatheory.Base.nt x e))) u352 (Pulse.Syntax.Naming.subst_term t1 (Pulse.Typing.Metatheory.Base.nt x e))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.var", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.pairwise_disjoint", "Pulse.Typing.Env.singleton_env", "Pulse.Typing.Env.fstar_env", "Pulse.Syntax.Base.term", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.universe", "Pulse.Typing.non_informative_t", "Pulse.Typing.Env.push_env", "Pulse.Typing.non_informative_witness_t", "Prims.Mkdtuple2", "Pulse.Typing.Env.subst_env", "Pulse.Typing.Metatheory.Base.nt", "Pulse.Syntax.Naming.subst_term", "Pulse.RuntimeUtils.magic", "Prims.list", "Pulse.Syntax.Naming.subst_elt" ]
[]
false
false
false
false
false
let non_informative_t_subst (g: env) (x: var) (t: typ) (g': env{pairwise_disjoint g (singleton_env (fstar_env g) x t) g'}) (#e: term) (e_typing: tot_typing g e t) (u: universe) (t1: term) (d: non_informative_t (push_env g (push_env (singleton_env (fstar_env g) x t) g')) u t1) : non_informative_t (push_env g (subst_env g' (nt x e))) u (subst_term t1 (nt x e)) =
let ss = nt x e in let (| w , _ |) = d in (| subst_term w ss, RU.magic #(tot_typing _ _ _) () |)
false
Printers.fst
Printers.print_Prims_int
val print_Prims_int: int -> Tot string
val print_Prims_int: int -> Tot string
let print_Prims_int : int -> Tot string = string_of_int
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 26, "start_col": 0, "start_line": 26 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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.int -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string_of_int" ]
[]
false
false
false
true
false
let print_Prims_int: int -> Tot string =
string_of_int
false
Printers.fst
Printers.print_Prims_string
val print_Prims_string: string -> Tot string
val print_Prims_string: string -> Tot string
let print_Prims_string : string -> Tot string = fun s -> "\"" ^ s ^ "\""
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 72, "end_line": 25, "start_col": 0, "start_line": 25 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.op_Hat" ]
[]
false
false
false
true
false
let print_Prims_string: string -> Tot string =
fun s -> "\"" ^ s ^ "\""
false
Printers.fst
Printers.mk_concat
val mk_concat (sep: term) (ts: list term) : Tac term
val mk_concat (sep: term) (ts: list term) : Tac term
let mk_concat (sep : term) (ts : list term) : Tac term = mk_e_app (pack (Tv_FVar (pack_fv ["FStar"; "String"; "concat"]))) [sep; mk_list ts]
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 87, "end_line": 29, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util let print_Prims_string : string -> Tot string = fun s -> "\"" ^ s ^ "\"" let print_Prims_int : int -> Tot string = string_of_int
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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
sep: FStar.Tactics.NamedView.term -> ts: Prims.list FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Reflection.V2.Derived.mk_e_app", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Prims.Cons", "Prims.string", "Prims.Nil", "FStar.Stubs.Reflection.Types.term", "FStar.Reflection.V2.Derived.mk_list" ]
[]
false
true
false
false
false
let mk_concat (sep: term) (ts: list term) : Tac term =
mk_e_app (pack (Tv_FVar (pack_fv ["FStar"; "String"; "concat"]))) [sep; mk_list ts]
false
Printers.fst
Printers.mk_flatten
val mk_flatten : ts: Prims.list FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
let mk_flatten ts = mk_concat (`"") ts
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 31, "start_col": 0, "start_line": 31 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util let print_Prims_string : string -> Tot string = fun s -> "\"" ^ s ^ "\"" let print_Prims_int : int -> Tot string = string_of_int let mk_concat (sep : term) (ts : list term) : Tac term = mk_e_app (pack (Tv_FVar (pack_fv ["FStar"; "String"; "concat"]))) [sep; mk_list ts]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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
ts: Prims.list FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Tactics.NamedView.term", "Printers.mk_concat" ]
[]
false
true
false
false
false
let mk_flatten ts =
mk_concat (`"") ts
false
Hacl.Impl.Chacha20.Vec.fst
Hacl.Impl.Chacha20.Vec.chacha20_encrypt_block
val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text)))
val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text)))
let chacha20_encrypt_block #w ctx out incr text = push_frame(); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame()
{ "file_name": "code/chacha20/Hacl.Impl.Chacha20.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 149, "start_col": 0, "start_line": 143 }
module Hacl.Impl.Chacha20.Vec module ST = FStar.HyperStack.ST open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.IntVector open Hacl.Impl.Chacha20.Core32xN module Spec = Hacl.Spec.Chacha20.Vec module Chacha20Equiv = Hacl.Spec.Chacha20.Equiv module Loop = Lib.LoopCombinators #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 200 --record_options" //#set-options "--debug Hacl.Impl.Chacha20.Vec --debug_level ExtractNorm" noextract val rounds: #w:lanes -> st:state w -> Stack unit (requires (fun h -> live h st)) (ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Spec.rounds (as_seq h0 st))) [@ Meta.Attribute.inline_ ] let rounds #w st = double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st; double_round st noextract val chacha20_core: #w:lanes -> k:state w -> ctx0:state w -> ctr:size_t{w * v ctr <= max_size_t} -> Stack unit (requires (fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)) (ensures (fun h0 _ h1 -> modifies (loc k) h0 h1 /\ as_seq h1 k == Spec.chacha20_core (v ctr) (as_seq h0 ctx0))) [@ Meta.Attribute.specialize ] let chacha20_core #w k ctx ctr = copy_state k ctx; let ctr_u32 = u32 w *! size_to_uint32 ctr in let cv = vec_load ctr_u32 w in k.(12ul) <- k.(12ul) +| cv; rounds k; sum_state k ctx; k.(12ul) <- k.(12ul) +| cv val chacha20_constants: b:glbuffer size_t 4ul{recallable b /\ witnessed b Spec.Chacha20.chacha20_constants} let chacha20_constants = [@ inline_let] let l = [Spec.c0;Spec.c1;Spec.c2;Spec.c3] in assert_norm(List.Tot.length l == 4); createL_global l inline_for_extraction noextract val setup1: ctx:lbuffer uint32 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (u32 0))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.setup1 (as_seq h0 k) (as_seq h0 n) (v ctr0))) let setup1 ctx k n ctr = let h0 = ST.get() in recall_contents chacha20_constants Spec.chacha20_constants; update_sub_f h0 ctx 0ul 4ul (fun h -> Lib.Sequence.map secret Spec.chacha20_constants) (fun _ -> mapT 4ul (sub ctx 0ul 4ul) secret chacha20_constants); let h1 = ST.get() in update_sub_f h1 ctx 4ul 8ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h k)) (fun _ -> uints_from_bytes_le (sub ctx 4ul 8ul) k); let h2 = ST.get() in ctx.(12ul) <- size_to_uint32 ctr; let h3 = ST.get() in update_sub_f h3 ctx 13ul 3ul (fun h -> Lib.ByteSequence.uints_from_bytes_le (as_seq h n)) (fun _ -> uints_from_bytes_le (sub ctx 13ul 3ul) n) inline_for_extraction noextract val chacha20_init: #w:lanes -> ctx:state w -> k:lbuffer uint8 32ul -> n:lbuffer uint8 12ul -> ctr0:size_t -> Stack unit (requires (fun h -> live h ctx /\ live h k /\ live h n /\ disjoint ctx k /\ disjoint ctx n /\ as_seq h ctx == Lib.Sequence.create 16 (vec_zero U32 w))) (ensures (fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\ as_seq h1 ctx == Spec.chacha20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))) [@ Meta.Attribute.specialize ] let chacha20_init #w ctx k n ctr = push_frame(); let ctx1 = create 16ul (u32 0) in setup1 ctx1 k n ctr; let h0 = ST.get() in mapT 16ul ctx (Spec.vec_load_i w) ctx1; let ctr = vec_counter U32 w in let c12 = ctx.(12ul) in ctx.(12ul) <- c12 +| ctr; pop_frame() noextract val chacha20_encrypt_block: #w:lanes -> ctx:state w -> out:lbuffer uint8 (size w *! 64ul) -> incr:size_t{w * v incr <= max_size_t} -> text:lbuffer uint8 (size w *! 64ul) -> Stack unit (requires (fun h -> live h ctx /\ live h text /\ live h out /\ disjoint out ctx /\ disjoint text ctx /\ eq_or_disjoint text out)) (ensures (fun h0 _ h1 -> modifies (loc out) h0 h1 /\ as_seq h1 out == Spec.chacha20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text)))
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Equiv.fst.checked", "Hacl.Impl.Chacha20.Core32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Chacha20.Vec.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Equiv", "short_module": "Chacha20Equiv" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20.Core32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20", "short_module": null }, { "abbrev": 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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ctx: Hacl.Impl.Chacha20.Core32xN.state w -> out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Lib.IntTypes.size w *! 64ul) -> incr: Lib.IntTypes.size_t{w * Lib.IntTypes.v incr <= Lib.IntTypes.max_size_t} -> text: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Lib.IntTypes.size w *! 64ul) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Chacha20.Core32xN.lanes", "Hacl.Impl.Chacha20.Core32xN.state", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.size", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.max_size_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Chacha20.Core32xN.xor_block", "Hacl.Impl.Chacha20.Core32xN.transpose", "Hacl.Impl.Chacha20.Vec.chacha20_core", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Hacl.Impl.Chacha20.Core32xN.uint32xN", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntVector.vec_zero", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let chacha20_encrypt_block #w ctx out incr text =
push_frame (); let k = create 16ul (vec_zero U32 w) in chacha20_core k ctx incr; transpose k; xor_block out k text; pop_frame ()
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.ffdhe_len
val ffdhe_len (a: S.ffdhe_alg) : x: size_pos{v x = S.ffdhe_len a}
val ffdhe_len (a: S.ffdhe_alg) : x: size_pos{v x = S.ffdhe_len a}
let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 42, "start_col": 0, "start_line": 35 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0}
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.FFDHE.ffdhe_alg -> x: Hacl.Impl.FFDHE.size_pos{Lib.IntTypes.v x = Spec.FFDHE.ffdhe_len a}
Prims.Tot
[ "total" ]
[]
[ "Spec.FFDHE.ffdhe_alg", "FStar.UInt32.__uint_to_t", "Hacl.Impl.FFDHE.size_pos", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Lib.IntTypes.U32", "Prims.l_and", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Spec.FFDHE.ffdhe_len", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
false
false
false
false
false
let ffdhe_len (a: S.ffdhe_alg) : x: size_pos{v x = S.ffdhe_len a} =
allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul
false
TwoLockQueue.fst
TwoLockQueue.intro_lock_inv
val intro_lock_inv (#a #u: _) (ptr: ref (Q.t a)) (ghost: ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v: Q.t a) -> (pts_to ptr full v) `star` (ghost_pts_to ghost half v))) (fun _ -> lock_inv ptr ghost)
val intro_lock_inv (#a #u: _) (ptr: ref (Q.t a)) (ghost: ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v: Q.t a) -> (pts_to ptr full v) `star` (ghost_pts_to ghost half v))) (fun _ -> lock_inv ptr ghost)
let intro_lock_inv #a #u (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (fun _ -> lock_inv ptr ghost) = assert_spinoff (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) == lock_inv ptr ghost); rewrite_slprop (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (lock_inv _ _) (fun _ -> ())
{ "file_name": "share/steel/examples/steel/TwoLockQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 19, "end_line": 92, "start_col": 0, "start_line": 83 }
module TwoLockQueue open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock module L = FStar.List.Tot module U = Steel.Utils module Q = Queue /// This module provides an implementation of Michael and Scott's two lock queue, using the /// abstract interface for queues provided in Queue.fsti. /// This implementation allows an enqueue and a dequeue operation to safely operate in parallel. /// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation, /// ensuring that at most one enqueue (resp. dequeue) is happening at any time /// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue #push-options "--ide_id_info_off" /// Adding the definition of the vprop equivalence to the context, for proof purposes let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) = Classical.forall_intro_2 reveal_equiv (* Some wrappers to reduce clutter in the code *) [@@__reduce__] let full = full_perm [@@__reduce__] let half = half_perm full (* Wrappers around fst and snd to avoid overnormalization. TODO: The frame inference tactic should not normalize fst and snd *) let fst x = fst x let snd x = snd x (* Some wrappers around Steel functions which are easier to use inside this module *) let ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1}) (x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r p x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1) = let _ = ghost_gather_pt #a #u #p0 #p1 r in () let rewrite #u (p q:vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) = rewrite_slprop p q (fun _ -> reveal_equiv p q) let elim_pure (#p:prop) #u () : SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) = let _ = Steel.Effect.Atomic.elim_pure p in () let open_exists (#a:Type) (#opened_invariants:_) (#p:a -> vprop) (_:unit) : SteelGhostT (Ghost.erased a) opened_invariants (h_exists p) (fun r -> p (reveal r)) = let v : erased a = witness_exists () in v (*** Queue invariant ***) /// The invariant associated to the lock. Basically a variant of the /// Owicki-Gries invariant, but applied to queues [@@__reduce__] let lock_inv #a (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) = h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Queue.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "TwoLockQueue.fst" }
[ { "abbrev": true, "full_module": "Queue", "short_module": "Q" }, { "abbrev": true, "full_module": "Steel.Utils", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": 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
ptr: Steel.Reference.ref (Queue.Def.t a) -> ghost: Steel.Reference.ghost_ref (Queue.Def.t a) -> Steel.Effect.Atomic.SteelGhostT Prims.unit
Steel.Effect.Atomic.SteelGhostT
[]
[]
[ "Steel.Memory.inames", "Steel.Reference.ref", "Queue.Def.t", "Steel.Reference.ghost_ref", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Effect.Atomic.h_exists", "Steel.Effect.Common.star", "Steel.Reference.pts_to", "TwoLockQueue.full", "Steel.Reference.ghost_pts_to", "TwoLockQueue.half", "Steel.Effect.Common.vprop", "TwoLockQueue.lock_inv", "Steel.Memory.mem", "Prims.unit", "FStar.Pervasives.assert_spinoff", "Prims.eq2" ]
[]
false
true
false
false
false
let intro_lock_inv #a #u (ptr: ref (Q.t a)) (ghost: ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v: Q.t a) -> (pts_to ptr full v) `star` (ghost_pts_to ghost half v))) (fun _ -> lock_inv ptr ghost) =
assert_spinoff (h_exists (fun (v: Q.t a) -> (pts_to ptr full v) `star` (ghost_pts_to ghost half v)) == lock_inv ptr ghost); rewrite_slprop (h_exists (fun (v: Q.t a) -> (pts_to ptr full v) `star` (ghost_pts_to ghost half v))) (lock_inv _ _) (fun _ -> ())
false
Printers.fst
Printers.paren
val paren (e: term) : Tac term
val paren (e: term) : Tac term
let paren (e : term) : Tac term = mk_flatten [mk_stringlit "("; e; mk_stringlit ")"]
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 34, "start_col": 0, "start_line": 33 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util let print_Prims_string : string -> Tot string = fun s -> "\"" ^ s ^ "\"" let print_Prims_int : int -> Tot string = string_of_int let mk_concat (sep : term) (ts : list term) : Tac term = mk_e_app (pack (Tv_FVar (pack_fv ["FStar"; "String"; "concat"]))) [sep; mk_list ts] let mk_flatten ts = mk_concat (`"") ts
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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
e: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "Printers.mk_flatten", "Prims.Cons", "FStar.Reflection.V2.Derived.mk_stringlit", "Prims.Nil" ]
[]
false
true
false
false
false
let paren (e: term) : Tac term =
mk_flatten [mk_stringlit "("; e; mk_stringlit ")"]
false
Printers.fst
Printers.mk_print_bv
val mk_print_bv (self: name) (f: term) (bvty: namedv & typ) : Tac term
val mk_print_bv (self: name) (f: term) (bvty: namedv & typ) : Tac term
let mk_print_bv (self : name) (f : term) (bvty : namedv & typ) : Tac term = let bv, ty = bvty in (* debug ("self = " ^ String.concat "." self ^ "\n>>>>>> f = : " ^ term_to_string f); *) let mk n = pack (Tv_FVar (pack_fv n)) in match inspect ty with | Tv_FVar fv -> if inspect_fv fv = self then mk_e_app f [pack (Tv_Var bv)] else let f = mk (cur_module () @ ["print_" ^ (String.concat "_" (inspect_fv fv))]) in mk_e_app f [pack (Tv_Var bv)] | _ -> mk_stringlit "?"
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 47, "start_col": 0, "start_line": 36 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util let print_Prims_string : string -> Tot string = fun s -> "\"" ^ s ^ "\"" let print_Prims_int : int -> Tot string = string_of_int let mk_concat (sep : term) (ts : list term) : Tac term = mk_e_app (pack (Tv_FVar (pack_fv ["FStar"; "String"; "concat"]))) [sep; mk_list ts] let mk_flatten ts = mk_concat (`"") ts let paren (e : term) : Tac term = mk_flatten [mk_stringlit "("; e; mk_stringlit ")"]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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
self: FStar.Stubs.Reflection.Types.name -> f: FStar.Tactics.NamedView.term -> bvty: (FStar.Tactics.NamedView.namedv * FStar.Stubs.Reflection.Types.typ) -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.name", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.namedv", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.Types.fv", "Prims.op_Equality", "FStar.Stubs.Reflection.V2.Builtins.inspect_fv", "FStar.Reflection.V2.Derived.mk_e_app", "Prims.Cons", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Var", "Prims.Nil", "Prims.bool", "FStar.List.Tot.Base.op_At", "Prims.string", "Prims.op_Hat", "FStar.String.concat", "Prims.list", "FStar.Tactics.V2.Derived.cur_module", "FStar.Tactics.NamedView.named_term_view", "FStar.Reflection.V2.Derived.mk_stringlit", "FStar.Tactics.NamedView.inspect", "FStar.Tactics.NamedView.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv" ]
[]
false
true
false
false
false
let mk_print_bv (self: name) (f: term) (bvty: namedv & typ) : Tac term =
let bv, ty = bvty in let mk n = pack (Tv_FVar (pack_fv n)) in match inspect ty with | Tv_FVar fv -> if inspect_fv fv = self then mk_e_app f [pack (Tv_Var bv)] else let f = mk (cur_module () @ ["print_" ^ (String.concat "_" (inspect_fv fv))]) in mk_e_app f [pack (Tv_Var bv)] | _ -> mk_stringlit "?"
false
MerkleTree.Low.fst
MerkleTree.Low.mt_get_path
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)))
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)))
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
{ "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": 3, "end_line": 2161, "start_col": 0, "start_line": 2075 }
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
{ "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.Low.const_mt_p -> idx: MerkleTree.Low.offset_t -> p: MerkleTree.Low.path_p -> root: MerkleTree.Low.Datastructures.hash -> FStar.HyperStack.ST.ST MerkleTree.Low.index_t
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.const_mt_p", "MerkleTree.Low.offset_t", "MerkleTree.Low.path_p", "MerkleTree.Low.Datastructures.hash", "FStar.Ghost.reveal", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Pervasives.Native.tuple3", "Prims.nat", "MerkleTree.New.High.path", "FStar.UInt32.v", "MerkleTree.Low.__proj__MT__item__hash_size", "LowStar.Monotonic.Buffer.get", "MerkleTree.Low.merkle_tree", "LowStar.Buffer.trivial_preorder", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.op_Addition", "MerkleTree.New.High.mt_path_length", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.Low.mt_lift", "MerkleTree.New.High.mt_get_path", "LowStar.Regional.__proj__Rgl__item__r_repr", "MerkleTree.Low.Datastructures.hreg", "FStar.Pervasives.Native.Mktuple3", "MerkleTree.Low.__proj__MT__item__j", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "MerkleTree.Low.lift_path", "FStar.Seq.Base.equal", "MerkleTree.New.High.mt_get_path_", "LowStar.RVector.as_seq", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Datastructures.hvreg", "MerkleTree.Low.mt_safe_elts_spec", "FStar.UInt32.__uint_to_t", "FStar.UInt32.t", "LowStar.Vector.size_of", "MerkleTree.Low.__proj__Path__item__hash_size", "MerkleTree.Low.path", "MerkleTree.Low.phashes", "FStar.Integers.op_Plus", "FStar.Integers.Unsigned", "FStar.Integers.W32", "MerkleTree.Low.mt_path_length", "LowStar.Regional.__proj__Rgl__item__r_inv", "MerkleTree.Low.path_safe", "MerkleTree.Low.mt_safe", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "MerkleTree.Low.mt_loc", "LowStar.Monotonic.Buffer.loc_all_regions_from", "LowStar.Monotonic.Buffer.frameOf", "Lib.IntTypes.uint8", "MerkleTree.Low.path_loc", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "MerkleTree.Low.mt_preserved", "MerkleTree.Low.mt_safe_preserved", "LowStar.Regional.__proj__Rgl__item__r_sep", "MerkleTree.Low.mt_get_path_loc_union_helper", "MerkleTree.Low.index_t", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "MerkleTree.Low.mt_get_path_", "MerkleTree.New.High.path_insert", "FStar.Seq.Base.index", "LowStar.Regional.__proj__Rgl__item__repr", "FStar.Integers.op_Subtraction", "MerkleTree.Low.mt_path_insert", "LowStar.Vector.index", "LowStar.Vector.vector", "MerkleTree.Low.Datastructures.hash_vv_as_seq_get_index", "MerkleTree.Low.Datastructures.hash_vv_rv_inv_r_inv", "MerkleTree.Low.Datastructures.hash_vv_rv_inv_includes", "FStar.Integers.op_Less", "LowStar.Vector.get", "MerkleTree.Low.mt_safe_elts", "LowStar.Vector.uint32_t", "MerkleTree.Low.merkle_tree_size_lg", "MerkleTree.Low.__proj__MT__item__rhs", "MerkleTree.Low.Datastructures.hash_vv", "MerkleTree.Low.__proj__MT__item__hs", "Prims.l_and", "FStar.UInt32.lte", "MerkleTree.Low.__proj__MT__item__i", "MerkleTree.Low.add64_fits", "MerkleTree.Low.__proj__MT__item__offset", "MerkleTree.Low.offset_of", "MerkleTree.Low.split_offset", "FStar.Seq.Base.empty", "FStar.Pervasives.Native.tuple2", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_get_root", "FStar.Pervasives.Native.Mktuple2", "MerkleTree.Low.path_safe_init_preserved", "LowStar.BufferOps.op_Bang_Star", "MerkleTree.Low.mt_get_root", "FStar.Monotonic.HyperHeap.rid", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.ConstBuffer.cast" ]
[]
false
true
false
false
false
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 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); 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
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.ffdhe_precomp_p_st
val ffdhe_precomp_p_st : t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
let ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> Stack unit (requires fun h -> live h p_r2_n /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 _ h1 -> modifies (loc p_r2_n) h0 h1 /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 p_r2_n))
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 133, "start_col": 0, "start_line": 124 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s)) let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) inline_for_extraction noextract let ffdhe_bn_from_g_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = g_n:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a))) inline_for_extraction noextract val ffdhe_bn_from_g: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ffdhe_bn_from_g_st t a len let ffdhe_bn_from_g #t a len g_n = recall_contents ffdhe_g2 S.ffdhe_g2; [@inline_let] let nLen = blocks len (size (numbytes t)) in push_frame (); let g = create 1ul (u8 0) in mapT 1ul g secret ffdhe_g2; BSeq.nat_from_intseq_be_public_to_secret 1 S.ffdhe_g2; let h0 = ST.get () in update_sub_f h0 g_n 0ul 1ul (fun h -> SB.bn_from_bytes_be 1 (as_seq h0 g)) (fun _ -> BN.bn_from_bytes_be 1ul g (sub g_n 0ul 1ul)); let h1 = ST.get () in SD.bn_eval_update_sub #t 1 (SB.bn_from_bytes_be 1 (as_seq h0 g)) (v nLen); assert (bn_v h1 g_n == SD.bn_v (SB.bn_from_bytes_be #t 1 (as_seq h0 g))); SB.bn_from_bytes_be_lemma #t 1 (as_seq h0 g); assert (bn_v h1 g_n == BSeq.nat_from_bytes_be (as_seq h0 g)); pop_frame () inline_for_extraction noextract let ffdhe_precomp_inv (#t:limb_t) (#len:size_nat{0 < len /\ len + len <= max_size_t}) (a:S.ffdhe_alg) (p_r2_n:SD.lbignum t (len + len)) = let p_n = LSeq.sub p_r2_n 0 len in let r2_n = LSeq.sub p_r2_n len len in SD.bn_v p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ 0 < SD.bn_v p_n /\ SD.bn_v r2_n == pow2 (2 * bits t * len) % SD.bn_v p_n
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Spec.FFDHE.ffdhe_alg", "Hacl.Impl.FFDHE.size_pos", "Hacl.Bignum.Exponentiation.exp", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.IntTypes.v", "Spec.FFDHE.ffdhe_len", "Prims.eq2", "Lib.IntTypes.size_t", "FStar.Mul.op_Star", "Lib.IntTypes.size", "Lib.IntTypes.numbytes", "Hacl.Spec.Bignum.Definitions.blocks", "Prims.op_LessThan", "Lib.IntTypes.bits", "Hacl.Bignum.__proj__Mkbn__item__len", "Hacl.Bignum.Exponentiation.__proj__Mkexp__item__bn", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Hacl.Impl.FFDHE.ffdhe_precomp_inv", "Lib.Buffer.as_seq", "Lib.IntTypes.int_t", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_Multiply", "Lib.IntTypes.mk_int", "Hacl.Bignum.Definitions.blocks" ]
[]
false
false
false
false
true
let ffdhe_precomp_p_st (t: limb_t) (a: S.ffdhe_alg) (len: size_pos) (ke: BE.exp t) =
let nLen = blocks len (size (numbytes t)) in p_r2_n: lbignum t (nLen +! nLen) -> Stack unit (requires fun h -> live h p_r2_n /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 _ h1 -> modifies (loc p_r2_n) h0 h1 /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 p_r2_n))
false
Printers.fst
Printers.mk_printer_type
val mk_printer_type (t: term) : Tac term
val mk_printer_type (t: term) : Tac term
let mk_printer_type (t : term) : Tac term = let b = fresh_binder_named "arg" t in let str = pack (Tv_FVar (pack_fv string_lid)) in let c = pack_comp (C_Total str) in pack (Tv_Arrow b c)
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 53, "start_col": 0, "start_line": 49 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util let print_Prims_string : string -> Tot string = fun s -> "\"" ^ s ^ "\"" let print_Prims_int : int -> Tot string = string_of_int let mk_concat (sep : term) (ts : list term) : Tac term = mk_e_app (pack (Tv_FVar (pack_fv ["FStar"; "String"; "concat"]))) [sep; mk_list ts] let mk_flatten ts = mk_concat (`"") ts let paren (e : term) : Tac term = mk_flatten [mk_stringlit "("; e; mk_stringlit ")"] let mk_print_bv (self : name) (f : term) (bvty : namedv & typ) : Tac term = let bv, ty = bvty in (* debug ("self = " ^ String.concat "." self ^ "\n>>>>>> f = : " ^ term_to_string f); *) let mk n = pack (Tv_FVar (pack_fv n)) in match inspect ty with | Tv_FVar fv -> if inspect_fv fv = self then mk_e_app f [pack (Tv_Var bv)] else let f = mk (cur_module () @ ["print_" ^ (String.concat "_" (inspect_fv fv))]) in mk_e_app f [pack (Tv_Var bv)] | _ -> mk_stringlit "?"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Arrow", "FStar.Tactics.NamedView.comp", "FStar.Tactics.NamedView.pack_comp", "FStar.Stubs.Reflection.V2.Data.C_Total", "FStar.Tactics.NamedView.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Reflection.Const.string_lid", "FStar.Tactics.NamedView.simple_binder", "FStar.Tactics.V2.Derived.fresh_binder_named" ]
[]
false
true
false
false
false
let mk_printer_type (t: term) : Tac term =
let b = fresh_binder_named "arg" t in let str = pack (Tv_FVar (pack_fv string_lid)) in let c = pack_comp (C_Total str) in pack (Tv_Arrow b c)
false
Pulse.Typing.Metatheory.Base.fst
Pulse.Typing.Metatheory.Base.lift_comp_subst
val lift_comp_subst (g: env) (x: var) (t: typ) (g': env{pairwise_disjoint g (singleton_env (fstar_env g) x t) g'}) (#e: term) (e_typing: tot_typing g e t) (#c1 #c2: comp) (d: lift_comp (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c1 c2) : lift_comp (push_env g (subst_env g' (nt x e))) (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e))
val lift_comp_subst (g: env) (x: var) (t: typ) (g': env{pairwise_disjoint g (singleton_env (fstar_env g) x t) g'}) (#e: term) (e_typing: tot_typing g e t) (#c1 #c2: comp) (d: lift_comp (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c1 c2) : lift_comp (push_env g (subst_env g' (nt x e))) (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e))
let lift_comp_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (#c1 #c2:comp) (d:lift_comp (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c1 c2) : lift_comp (push_env g (subst_env g' (nt x e))) (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e)) = let ss = nt x e in match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ (subst_comp c ss) | Lift_Ghost_Neutral _ c d_non_informative -> Lift_Ghost_Neutral _ (subst_comp c ss) (non_informative_c_subst g x t g' e_typing _ d_non_informative) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ (subst_comp c ss) | Lift_Observability _ c o -> Lift_Observability _ (subst_comp c ss) o
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 487, "start_col": 0, "start_line": 462 }
(* 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.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing let admit_st_comp_typing (g:env) (st:st_comp) : st_comp_typing g st = admit(); STC g st (fresh g) (admit()) (admit()) (admit()) let admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c = match c with | C_ST st -> CT_ST g st (admit_st_comp_typing g st) | C_STAtomic inames obs st -> CT_STAtomic g inames obs st (admit()) (admit_st_comp_typing g st) | C_STGhost st -> CT_STGhost g st (admit_st_comp_typing g st) let st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c}) (_:st_typing g t c) : (u:Ghost.erased universe & universe_of g (comp_res c) u) = let u : Ghost.erased universe = RU.magic () in let ty : universe_of g (comp_res c) u = RU.magic() in (| u, ty |) let st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c = admit_comp_typing g c let add_frame_well_typed (#g:env) (#c:comp_st) (ct:comp_typing_u g c) (#f:term) (ft:tot_typing g f tm_vprop) : comp_typing_u g (add_frame c f) = admit_comp_typing _ _ let emp_inames_typing (g:env) : tot_typing g tm_emp_inames tm_inames = RU.magic() let comp_typing_inversion #g #c ct = match ct with | CT_ST _ _ st | CT_STGhost _ _ st -> st, emp_inames_typing g | CT_STAtomic _ _ _ _ it st -> st, it let st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) = admit(), admit(), (fun _ -> admit()) let st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) = let STC g st x ty pre post = ct in (| ty, pre, x, post |) let tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop = admit(), admit() let pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) = admit () let typing_correctness _ = admit() let tot_typing_renaming1 _ _ _ _ _ _ = admit() let tot_typing_weakening _ _ _ _ _ _ = admit () let non_informative_t_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (u:universe) (t:term) (d:non_informative_t (push_env g g') u t) : non_informative_t (push_env (push_env g g1) g') u t = let (| w, _ |) = d in (| w, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_weakening (g g':env) (g1:env{ pairwise_disjoint g g1 g' }) (c:comp_st) (d:non_informative_c (push_env g g') c) : non_informative_c (push_env (push_env g g1) g') c = non_informative_t_weakening g g' g1 _ _ d let bind_comp_weakening (g:env) (g':env { disjoint g g' }) (#x:var) (#c1 #c2 #c3:comp) (d:bind_comp (push_env g g') x c1 c2 c3) (g1:env { pairwise_disjoint g g1 g' }) : Tot (bind_comp (push_env (push_env g g1) g') x c1 c2 c3) (decreases d) = match d with | Bind_comp _ x c1 c2 _ _ _ -> assume (None? (lookup (push_env g g1) x)); let y = fresh (push_env (push_env g g1) g') in assume (~ (y `Set.mem` (freevars (comp_post c2)))); Bind_comp _ x c1 c2 (RU.magic ()) y (RU.magic ()) let lift_comp_weakening (g:env) (g':env { disjoint g g'}) (#c1 #c2:comp) (d:lift_comp (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (lift_comp (push_env (push_env g g1) g') c1 c2) (decreases d) = match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ c | Lift_Ghost_Neutral _ c non_informative_c -> Lift_Ghost_Neutral _ c (non_informative_c_weakening g g' g1 _ non_informative_c) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ c | Lift_Observability _ obs c -> Lift_Observability _ obs c #push-options "--admit_smt_queries true" let st_equiv_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_equiv (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : st_equiv (push_env (push_env g g1) g') c1 c2 = match d with | ST_VPropEquiv _ c1 c2 x _ _ _ _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); // TODO: the proof for RT.Equiv is not correct here ST_VPropEquiv _ c1 c2 x (RU.magic ()) (RU.magic ()) (RU.magic ()) (FStar.Reflection.Typing.Rel_refl _ _ _) (RU.magic ()) (RU.magic ()) #pop-options // TODO: add precondition that g1 extends g' let prop_validity_token_weakening (#g:env) (#t:term) (token:prop_validity g t) (g1:env) : prop_validity g1 t = admit (); token let rec st_sub_weakening (g:env) (g':env { disjoint g g' }) (#c1 #c2:comp) (d:st_sub (push_env g g') c1 c2) (g1:env { pairwise_disjoint g g1 g' }) : Tot (st_sub (push_env (push_env g g1) g') c1 c2) (decreases d) = let g'' = push_env (push_env g g1) g' in match d with | STS_Refl _ _ -> STS_Refl _ _ | STS_Trans _ _ _ _ dl dr -> STS_Trans _ _ _ _ (st_sub_weakening g g' dl g1) (st_sub_weakening g g' dr g1) | STS_AtomicInvs _ stc is1 is2 o1 o2 tok -> let tok : prop_validity g'' (tm_inames_subset is1 is2) = prop_validity_token_weakening tok g'' in STS_AtomicInvs g'' stc is1 is2 o1 o2 tok let st_comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#s:st_comp) (d:st_comp_typing (push_env g g') s) (g1:env { pairwise_disjoint g g1 g' }) : st_comp_typing (push_env (push_env g g1) g') s = match d with | STC _ st x _ _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); STC _ st x (RU.magic ()) (RU.magic ()) (RU.magic ()) let comp_typing_weakening (g:env) (g':env { disjoint g g' }) (#c:comp) (#u:universe) (d:comp_typing (push_env g g') c u) (g1:env { pairwise_disjoint g g1 g' }) : comp_typing (push_env (push_env g g1) g') c u = match d with | CT_Tot _ t u _ -> CT_Tot _ t u (RU.magic ()) | CT_ST _ _ d -> CT_ST _ _ (st_comp_typing_weakening g g' d g1) | CT_STAtomic _ inames obs _ _ d -> CT_STAtomic _ inames obs _ (RU.magic ()) (st_comp_typing_weakening g g' d g1) | CT_STGhost _ _ d -> CT_STGhost _ _ (st_comp_typing_weakening g g' d g1) #push-options "--split_queries no --z3rlimit_factor 8 --fuel 1 --ifuel 1" let rec st_typing_weakening g g' t c d g1 : Tot (st_typing (push_env (push_env g g1) g') t c) (decreases d) = match d with | T_Abs g x q b u body c b_typing body_typing -> // T_Abs is used only at the top, should not come up assume false; let x = fresh (push_env (push_env g g1) g') in T_Abs g x q b u body c (RU.magic #(tot_typing _ _ _) ()) (st_typing_weakening g g' body c body_typing g1) | T_STApp _ head ty q res arg _ _ -> T_STApp _ head ty q res arg (RU.magic #(tot_typing _ _ _) ()) (RU.magic #(tot_typing _ _ _) ()) | T_STGhostApp _ head ty q res arg _ _ _ _ -> // candidate for renaming let x = fresh (push_env (push_env g g1) g') in assume (~ (x `Set.mem` freevars_comp res)); T_STGhostApp _ head ty q res arg x (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_Return _ c use_eq u t e post x_old _ _ _ -> let x = fresh (push_env (push_env g g1) g') in assume (~ (x `Set.mem` freevars post)); // x is only used to open and then close assume (comp_return c use_eq u t e post x_old == comp_return c use_eq u t e post x); T_Return _ c use_eq u t e post x (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_Lift _ e c1 c2 d_c1 d_lift -> T_Lift _ e c1 c2 (st_typing_weakening g g' e c1 d_c1 g1) (lift_comp_weakening g g' d_lift g1) | T_Bind _ e1 e2 c1 c2 b x c d_e1 _ d_e2 d_bc -> let d_e1 : st_typing (push_env (push_env g g1) g') e1 c1 = st_typing_weakening g g' e1 c1 d_e1 g1 in // // When we call it, g' will actually be empty // And they way bind checker invokes the lemma, we also know x is not in g1 // But we must fix it cleanly // Perhaps typing rules should take a thunk, fun (x:var) ... // assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_e2 : st_typing (push_binding (push_env g g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in assert (equal (push_binding (push_env g g') x ppname_default (comp_res c1)) (push_env g (push_binding g' x ppname_default (comp_res c1)))); let d_e2 : st_typing (push_env g (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = st_typing_weakening g (push_binding g' x ppname_default (comp_res c1)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_bc = bind_comp_weakening g g' d_bc g1 in T_Bind _ e1 e2 c1 c2 b x c d_e1 (RU.magic ()) d_e2 d_bc | T_BindFn _ e1 e2 c1 c2 b x d_e1 u _ d_e2 c2_typing -> let d_e1 : st_typing (push_env (push_env g g1) g') e1 c1 = st_typing_weakening g g' e1 c1 d_e1 g1 in // // When we call it, g' will actually be empty // And they way bind checker invokes the lemma, we also know x is not in g1 // But we must fix it cleanly // Perhaps typing rules should take a thunk, fun (x:var) ... // assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_e2 : st_typing (push_binding (push_env g g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in assert (equal (push_binding (push_env g g') x ppname_default (comp_res c1)) (push_env g (push_binding g' x ppname_default (comp_res c1)))); let d_e2 : st_typing (push_env g (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = st_typing_weakening g (push_binding g' x ppname_default (comp_res c1)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (comp_res c1))) (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 = d_e2 in let c2_typing = comp_typing_weakening g g' c2_typing g1 in T_BindFn _ e1 e2 c1 c2 b x d_e1 u (RU.magic #(tot_typing _ _ _) ()) d_e2 c2_typing | T_If _ b e1 e2 c hyp _ d_e1 d_e2 _ -> assume (~ (hyp `Set.mem` dom g')); assume (~ (hyp `Set.mem` dom g1)); let d_e1 : st_typing (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c = d_e1 in assert (equal (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)))); let d_e1 : st_typing (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) e1 c = d_e1 in let d_e1 : st_typing (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) e1 c = st_typing_weakening g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) _ _ d_e1 g1 in assert (equal (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))) (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true))); let d_e1 : st_typing (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c = d_e1 in let d_e2 : st_typing (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c = d_e2 in assert (equal (push_binding (push_env g g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)))); let d_e2 : st_typing (push_env g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) e2 c = d_e2 in let d_e2 : st_typing (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) e2 c = st_typing_weakening g (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) _ _ d_e2 g1 in assert (equal (push_env (push_env g g1) (push_binding g' hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))) (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false))); let d_e2 : st_typing (push_binding (push_env (push_env g g1) g') hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c = d_e2 in T_If _ b e1 e2 c hyp (RU.magic ()) d_e1 d_e2 (RU.magic ()) | T_Match _ sc_u sc_ty sc d_sc_ty d_sc c c_typing brs d_brs d_pats_complete -> admit(); T_Match (push_env (push_env g g1) g') sc_u sc_ty sc (tot_typing_weakening g g' _ _ d_sc_ty g1) (tot_typing_weakening g g' _ _ d_sc g1) c c_typing brs d_brs d_pats_complete | T_Frame _ e c frame _ d_e -> T_Frame _ e c frame (RU.magic ()) (st_typing_weakening g g' e c d_e g1) | T_Equiv _ e c c' d_e d_eq -> T_Equiv _ e c c' (st_typing_weakening g g' e c d_e g1) (st_equiv_weakening g g' d_eq g1) | T_Sub _ e c c' d_e d_sub -> T_Sub _ e c c' (st_typing_weakening g g' e c d_e g1) (st_sub_weakening g g' d_sub g1) | T_IntroPure _ p _ token -> T_IntroPure _ p (RU.magic ()) (prop_validity_token_weakening token _) | T_ElimExists _ u t p x _ _ -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); T_ElimExists _ u t p x (RU.magic ()) (RU.magic ()) | T_IntroExists _ u b p e _ _ _ -> T_IntroExists _ u b p e (RU.magic ()) (RU.magic ()) (RU.magic ()) | T_While _ inv cond body _ cond_typing body_typing -> T_While _ inv cond body (RU.magic ()) (st_typing_weakening g g' cond (comp_while_cond ppname_default inv) cond_typing g1) (st_typing_weakening g g' body (comp_while_body ppname_default inv) body_typing g1) | T_Par _ eL cL eR cR x cL_typing cR_typing eL_typing eR_typing -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); T_Par _ eL cL eR cR x (comp_typing_weakening g g' cL_typing g1) (comp_typing_weakening g g' cR_typing g1) (st_typing_weakening g g' eL cL eL_typing g1) (st_typing_weakening g g' eR cR eR_typing g1) | T_WithLocal _ ppname init body init_t c x _ _ d_c d_body -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_body : st_typing (push_binding (push_env g g') x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in assert (equal (push_binding (push_env g g') x ppname_default (mk_ref init_t)) (push_env g (push_binding g' x ppname_default (mk_ref init_t)))); let d_body : st_typing (push_env g (push_binding g' x ppname_default (mk_ref init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in let d_body : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (mk_ref init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = st_typing_weakening g (push_binding g' x ppname_default (mk_ref init_t)) _ _ d_body g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (mk_ref init_t))) (push_binding (push_env (push_env g g1) g') x ppname_default (mk_ref init_t))); let d_body : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) = d_body in T_WithLocal _ ppname init body init_t c x (RU.magic ()) (RU.magic ()) (comp_typing_weakening g g' d_c g1) d_body | T_WithLocalArray _ ppname init len body init_t c x _ _ _ d_c d_body -> assume (~ (x `Set.mem` dom g')); assume (~ (x `Set.mem` dom g1)); let d_body : st_typing (push_binding (push_env g g') x ppname_default (mk_array init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in assert (equal (push_binding (push_env g g') x ppname_default (mk_array init_t)) (push_env g (push_binding g' x ppname_default (mk_array init_t)))); let d_body : st_typing (push_env g (push_binding g' x ppname_default (mk_array init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in let d_body : st_typing (push_env (push_env g g1) (push_binding g' x ppname_default (mk_array init_t))) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = st_typing_weakening g (push_binding g' x ppname_default (mk_array init_t)) _ _ d_body g1 in assert (equal (push_env (push_env g g1) (push_binding g' x ppname_default (mk_array init_t))) (push_binding (push_env (push_env g g1) g') x ppname_default (mk_array init_t))); let d_body : st_typing (push_binding (push_env (push_env g g1) g') x ppname_default (mk_array init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x init_t init len c) = d_body in T_WithLocalArray _ ppname init len body init_t c x (RU.magic ()) (RU.magic ()) (RU.magic ()) (comp_typing_weakening g g' d_c g1) d_body | T_Rewrite _ p q _ _ -> T_Rewrite _ p q (RU.magic ()) (RU.magic ()) | T_Admit _ s c d_s -> T_Admit _ s c (st_comp_typing_weakening g g' d_s g1) | T_Unreachable _ s c d_s tok -> T_Unreachable _ s c (st_comp_typing_weakening g g' d_s g1) (RU.magic())//weaken tok | T_WithInv _ _ _ p_typing inv_typing _ _ body_typing tok -> T_WithInv _ _ _ (tot_typing_weakening g g' _ _ p_typing g1) (tot_typing_weakening g g' _ _ inv_typing g1) _ _ (st_typing_weakening g g' _ _ body_typing g1) (prop_validity_token_weakening tok _) #pop-options #push-options "--admit_smt_queries true" let non_informative_t_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (u:universe) (t1:term) (d:non_informative_t (push_env g (push_env (singleton_env (fstar_env g) x t) g')) u t1) : non_informative_t (push_env g (subst_env g' (nt x e))) u (subst_term t1 (nt x e)) = let ss = nt x e in let (| w, _ |) = d in (| subst_term w ss, RU.magic #(tot_typing _ _ _) () |) let non_informative_c_subst (g:env) (x:var) (t:typ) (g':env { pairwise_disjoint g (singleton_env (fstar_env g) x t) g' }) (#e:term) (e_typing:tot_typing g e t) (c:comp) (d:non_informative_c (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c) : non_informative_c (push_env g (subst_env g' (nt x e))) (subst_comp c (nt x e)) = non_informative_t_subst g x t g' e_typing _ _ d
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Typing.Metatheory.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.Stubs.TypeChecker.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": 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
g: Pulse.Typing.Env.env -> x: Pulse.Syntax.Base.var -> t: Pulse.Syntax.Base.typ -> g': Pulse.Typing.Env.env { Pulse.Typing.Env.pairwise_disjoint g (Pulse.Typing.Env.singleton_env (Pulse.Typing.Env.fstar_env g) x t) g' } -> e_typing: Pulse.Typing.tot_typing g e t -> d: Pulse.Typing.lift_comp (Pulse.Typing.Env.push_env g (Pulse.Typing.Env.push_env (Pulse.Typing.Env.singleton_env (Pulse.Typing.Env.fstar_env g ) x t) g')) c1 c2 -> Pulse.Typing.lift_comp (Pulse.Typing.Env.push_env g (Pulse.Typing.Env.subst_env g' (Pulse.Typing.Metatheory.Base.nt x e))) (Pulse.Syntax.Naming.subst_comp c1 (Pulse.Typing.Metatheory.Base.nt x e)) (Pulse.Syntax.Naming.subst_comp c2 (Pulse.Typing.Metatheory.Base.nt x e))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.var", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.pairwise_disjoint", "Pulse.Typing.Env.singleton_env", "Pulse.Typing.Env.fstar_env", "Pulse.Syntax.Base.term", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.comp", "Pulse.Typing.lift_comp", "Pulse.Typing.Env.push_env", "Pulse.Syntax.Base.comp_st", "Prims.b2t", "Pulse.Syntax.Base.uu___is_C_STAtomic", "Pulse.Typing.Lift_STAtomic_ST", "Pulse.Typing.Env.subst_env", "Pulse.Typing.Metatheory.Base.nt", "Pulse.Syntax.Naming.subst_comp", "Pulse.Syntax.Base.uu___is_C_STGhost", "Pulse.Typing.non_informative_c", "Pulse.Typing.Lift_Ghost_Neutral", "Pulse.Typing.Metatheory.Base.non_informative_c_subst", "Prims.l_and", "Prims.eq2", "Pulse.Syntax.Base.observability", "Pulse.Syntax.Base.__proj__C_STAtomic__item__obs", "Pulse.Syntax.Base.Neutral", "Pulse.Typing.Lift_Neutral_Ghost", "Pulse.Typing.sub_observability", "Pulse.Typing.Lift_Observability", "Prims.list", "Pulse.Syntax.Naming.subst_elt" ]
[]
false
false
false
false
false
let lift_comp_subst (g: env) (x: var) (t: typ) (g': env{pairwise_disjoint g (singleton_env (fstar_env g) x t) g'}) (#e: term) (e_typing: tot_typing g e t) (#c1 #c2: comp) (d: lift_comp (push_env g (push_env (singleton_env (fstar_env g) x t) g')) c1 c2) : lift_comp (push_env g (subst_env g' (nt x e))) (subst_comp c1 (nt x e)) (subst_comp c2 (nt x e)) =
let ss = nt x e in match d with | Lift_STAtomic_ST _ c -> Lift_STAtomic_ST _ (subst_comp c ss) | Lift_Ghost_Neutral _ c d_non_informative -> Lift_Ghost_Neutral _ (subst_comp c ss) (non_informative_c_subst g x t g' e_typing _ d_non_informative) | Lift_Neutral_Ghost _ c -> Lift_Neutral_Ghost _ (subst_comp c ss) | Lift_Observability _ c o -> Lift_Observability _ (subst_comp c ss) o
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.ffdhe_bn_from_g_st
val ffdhe_bn_from_g_st : t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> Type0
let ffdhe_bn_from_g_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = g_n:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a)))
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 94, "end_line": 86, "start_col": 0, "start_line": 77 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s)) let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a))
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Spec.FFDHE.ffdhe_alg", "Hacl.Impl.FFDHE.size_pos", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size", "Lib.IntTypes.numbytes", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Lib.IntTypes.U32", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Spec.FFDHE.ffdhe_len", "Prims.eq2", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Lib.Sequence.create", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.nat", "Hacl.Bignum.Definitions.bn_v", "Lib.ByteSequence.nat_from_bytes_be", "Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_g", "Spec.FFDHE.get_ffdhe_params" ]
[]
false
false
false
true
true
let ffdhe_bn_from_g_st (t: limb_t) (a: S.ffdhe_alg) (len: size_pos) =
g_n: lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a)))
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.ffdhe_p_to_ps
val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s))
val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s))
let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a))
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 102, "end_line": 73, "start_col": 0, "start_line": 68 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s))
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.FFDHE.ffdhe_alg -> p_s: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Hacl.Impl.FFDHE.ffdhe_len a) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Spec.FFDHE.ffdhe_alg", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Impl.FFDHE.ffdhe_len", "Lib.ByteSequence.nat_from_intseq_be_public_to_secret", "Lib.IntTypes.U8", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p", "Spec.FFDHE.get_ffdhe_params", "Prims.unit", "Lib.Buffer.mapT", "Lib.Buffer.CONST", "Lib.IntTypes.pub_uint8", "Lib.IntTypes.secret", "Hacl.Impl.FFDHE.size_pos", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.l_and", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Spec.FFDHE.ffdhe_len", "Lib.Buffer.recall_contents", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Prims.eq2", "LowStar.ConstBuffer.qual", "LowStar.ConstBuffer.qual_of", "LowStar.ConstBuffer.IMMUTABLE", "Lib.Buffer.witnessed", "Lib.Buffer.recallable", "Hacl.Impl.FFDHE.get_ffdhe_p" ]
[]
false
true
false
false
false
let ffdhe_p_to_ps a p_s =
let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a))
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.ffdhe_precomp_inv
val ffdhe_precomp_inv : a: Spec.FFDHE.ffdhe_alg -> p_r2_n: Hacl.Spec.Bignum.Definitions.lbignum t (len + len) -> Prims.logical
let ffdhe_precomp_inv (#t:limb_t) (#len:size_nat{0 < len /\ len + len <= max_size_t}) (a:S.ffdhe_alg) (p_r2_n:SD.lbignum t (len + len)) = let p_n = LSeq.sub p_r2_n 0 len in let r2_n = LSeq.sub p_r2_n len len in SD.bn_v p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ 0 < SD.bn_v p_n /\ SD.bn_v r2_n == pow2 (2 * bits t * len) % SD.bn_v p_n
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 120, "start_col": 0, "start_line": 114 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s)) let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) inline_for_extraction noextract let ffdhe_bn_from_g_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = g_n:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a))) inline_for_extraction noextract val ffdhe_bn_from_g: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ffdhe_bn_from_g_st t a len let ffdhe_bn_from_g #t a len g_n = recall_contents ffdhe_g2 S.ffdhe_g2; [@inline_let] let nLen = blocks len (size (numbytes t)) in push_frame (); let g = create 1ul (u8 0) in mapT 1ul g secret ffdhe_g2; BSeq.nat_from_intseq_be_public_to_secret 1 S.ffdhe_g2; let h0 = ST.get () in update_sub_f h0 g_n 0ul 1ul (fun h -> SB.bn_from_bytes_be 1 (as_seq h0 g)) (fun _ -> BN.bn_from_bytes_be 1ul g (sub g_n 0ul 1ul)); let h1 = ST.get () in SD.bn_eval_update_sub #t 1 (SB.bn_from_bytes_be 1 (as_seq h0 g)) (v nLen); assert (bn_v h1 g_n == SD.bn_v (SB.bn_from_bytes_be #t 1 (as_seq h0 g))); SB.bn_from_bytes_be_lemma #t 1 (as_seq h0 g); assert (bn_v h1 g_n == BSeq.nat_from_bytes_be (as_seq h0 g)); pop_frame ()
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.FFDHE.ffdhe_alg -> p_r2_n: Hacl.Spec.Bignum.Definitions.lbignum t (len + len) -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Spec.FFDHE.ffdhe_alg", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.eq2", "Prims.nat", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.ByteSequence.nat_from_bytes_be", "Lib.IntTypes.PUB", "Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p", "Spec.FFDHE.get_ffdhe_params", "Prims.int", "Prims.op_Modulus", "Prims.pow2", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.l_Forall", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Lib.Sequence.sub", "Prims.logical" ]
[]
false
false
false
false
true
let ffdhe_precomp_inv (#t: limb_t) (#len: size_nat{0 < len /\ len + len <= max_size_t}) (a: S.ffdhe_alg) (p_r2_n: SD.lbignum t (len + len)) =
let p_n = LSeq.sub p_r2_n 0 len in let r2_n = LSeq.sub p_r2_n len len in SD.bn_v p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ 0 < SD.bn_v p_n /\ SD.bn_v r2_n == pow2 ((2 * bits t) * len) % SD.bn_v p_n
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.get_ffdhe_p
val get_ffdhe_p (a: S.ffdhe_alg) : x: glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x}
val get_ffdhe_p (a: S.ffdhe_alg) : x: glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x}
let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 55, "start_col": 0, "start_line": 46 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.FFDHE.ffdhe_alg -> x: Lib.Buffer.glbuffer Lib.IntTypes.pub_uint8 (Hacl.Impl.FFDHE.ffdhe_len a) { Lib.Buffer.witnessed x (Mk_ffdhe_params?.ffdhe_p (Spec.FFDHE.get_ffdhe_params a)) /\ Lib.Buffer.recallable x }
Prims.Tot
[ "total" ]
[]
[ "Spec.FFDHE.ffdhe_alg", "Hacl.Impl.FFDHE.Constants.ffdhe_p2048", "Hacl.Impl.FFDHE.Constants.ffdhe_p3072", "Hacl.Impl.FFDHE.Constants.ffdhe_p4096", "Hacl.Impl.FFDHE.Constants.ffdhe_p6144", "Hacl.Impl.FFDHE.Constants.ffdhe_p8192", "Lib.Buffer.glbuffer", "Lib.IntTypes.pub_uint8", "Hacl.Impl.FFDHE.ffdhe_len", "Prims.l_and", "Lib.Buffer.witnessed", "Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p", "Spec.FFDHE.get_ffdhe_params", "Lib.Buffer.recallable", "Lib.Buffer.CONST", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
false
false
false
false
false
let get_ffdhe_p (a: S.ffdhe_alg) : x: glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} =
allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.new_ffdhe_precomp_p_st
val new_ffdhe_precomp_p_st : t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
let new_ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in r:HS.rid -> ST (B.buffer (limb t)) (requires fun h -> ST.is_eternal_region r /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( B.len res == nLen +! nLen /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 (res <: lbignum t (nLen +! nLen)))))
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 86, "end_line": 179, "start_col": 0, "start_line": 165 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s)) let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) inline_for_extraction noextract let ffdhe_bn_from_g_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = g_n:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a))) inline_for_extraction noextract val ffdhe_bn_from_g: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ffdhe_bn_from_g_st t a len let ffdhe_bn_from_g #t a len g_n = recall_contents ffdhe_g2 S.ffdhe_g2; [@inline_let] let nLen = blocks len (size (numbytes t)) in push_frame (); let g = create 1ul (u8 0) in mapT 1ul g secret ffdhe_g2; BSeq.nat_from_intseq_be_public_to_secret 1 S.ffdhe_g2; let h0 = ST.get () in update_sub_f h0 g_n 0ul 1ul (fun h -> SB.bn_from_bytes_be 1 (as_seq h0 g)) (fun _ -> BN.bn_from_bytes_be 1ul g (sub g_n 0ul 1ul)); let h1 = ST.get () in SD.bn_eval_update_sub #t 1 (SB.bn_from_bytes_be 1 (as_seq h0 g)) (v nLen); assert (bn_v h1 g_n == SD.bn_v (SB.bn_from_bytes_be #t 1 (as_seq h0 g))); SB.bn_from_bytes_be_lemma #t 1 (as_seq h0 g); assert (bn_v h1 g_n == BSeq.nat_from_bytes_be (as_seq h0 g)); pop_frame () inline_for_extraction noextract let ffdhe_precomp_inv (#t:limb_t) (#len:size_nat{0 < len /\ len + len <= max_size_t}) (a:S.ffdhe_alg) (p_r2_n:SD.lbignum t (len + len)) = let p_n = LSeq.sub p_r2_n 0 len in let r2_n = LSeq.sub p_r2_n len len in SD.bn_v p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ 0 < SD.bn_v p_n /\ SD.bn_v r2_n == pow2 (2 * bits t * len) % SD.bn_v p_n inline_for_extraction noextract let ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> Stack unit (requires fun h -> live h p_r2_n /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 _ h1 -> modifies (loc p_r2_n) h0 h1 /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 p_r2_n)) inline_for_extraction noextract val ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p_st t a len ke let ffdhe_precomp_p #t a len ke p_r2_n = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n = sub p_r2_n 0ul nLen in let r2_n = sub p_r2_n nLen nLen in let p_s = create len (u8 0) in ffdhe_p_to_ps a p_s; let h0 = ST.get () in BN.bn_from_bytes_be len p_s p_n; let h1 = ST.get () in SB.bn_from_bytes_be_lemma #t (v len) (as_seq h0 p_s); assert (bn_v h1 p_n == BSeq.nat_from_bytes_be (as_seq h0 p_s)); S.ffdhe_p_lemma a; Lemmas.ffdhe_p_bits_lemma a; ke.BE.precompr2 (8ul *! len -! 1ul) p_n r2_n; SM.bn_precomp_r2_mod_n_lemma (8 * v len - 1) (as_seq h1 p_n); pop_frame ()
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Spec.FFDHE.ffdhe_alg", "Hacl.Impl.FFDHE.size_pos", "Hacl.Bignum.Exponentiation.exp", "FStar.Monotonic.HyperHeap.rid", "LowStar.Buffer.buffer", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.HyperStack.ST.is_eternal_region", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Lib.IntTypes.U32", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Spec.FFDHE.ffdhe_len", "Prims.eq2", "Lib.IntTypes.size_t", "FStar.Mul.op_Star", "Lib.IntTypes.size", "Lib.IntTypes.numbytes", "Hacl.Spec.Bignum.Definitions.blocks", "Prims.op_LessThan", "Lib.IntTypes.bits", "Hacl.Bignum.__proj__Mkbn__item__len", "Hacl.Bignum.Exponentiation.__proj__Mkexp__item__bn", "Prims.l_imp", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "Lib.IntTypes.op_Plus_Bang", "LowStar.Monotonic.Buffer.fresh_loc", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_region_only", "Hacl.Impl.FFDHE.ffdhe_precomp_inv", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.int_t", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_Multiply", "Lib.IntTypes.mk_int", "Hacl.Bignum.Definitions.blocks" ]
[]
false
false
false
false
true
let new_ffdhe_precomp_p_st (t: limb_t) (a: S.ffdhe_alg) (len: size_pos) (ke: BE.exp t) =
let nLen = blocks len (size (numbytes t)) in r: HS.rid -> ST (B.buffer (limb t)) (requires fun h -> ST.is_eternal_region r /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> (B.len res == nLen +! nLen /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 (res <: lbignum t (nLen +! nLen)))))
false
Printers.fst
Printers.maplast
val maplast (f: ('a -> 'a)) (l: list 'a) : list 'a
val maplast (f: ('a -> 'a)) (l: list 'a) : list 'a
let rec maplast (f : 'a -> 'a) (l : list 'a) : list 'a = match l with | [] -> [] | [x] -> [f x] | x::xs -> x :: (maplast f xs)
{ "file_name": "examples/tactics/Printers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 118, "start_col": 0, "start_line": 114 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Printers open FStar.List.Tot (* TODO: This is pretty much a blast-to-the-past of Meta-F*, we can do * much better now. *) open FStar.Tactics.V2 module TD = FStar.Tactics.V2.Derived module TU = FStar.Tactics.Util let print_Prims_string : string -> Tot string = fun s -> "\"" ^ s ^ "\"" let print_Prims_int : int -> Tot string = string_of_int let mk_concat (sep : term) (ts : list term) : Tac term = mk_e_app (pack (Tv_FVar (pack_fv ["FStar"; "String"; "concat"]))) [sep; mk_list ts] let mk_flatten ts = mk_concat (`"") ts let paren (e : term) : Tac term = mk_flatten [mk_stringlit "("; e; mk_stringlit ")"] let mk_print_bv (self : name) (f : term) (bvty : namedv & typ) : Tac term = let bv, ty = bvty in (* debug ("self = " ^ String.concat "." self ^ "\n>>>>>> f = : " ^ term_to_string f); *) let mk n = pack (Tv_FVar (pack_fv n)) in match inspect ty with | Tv_FVar fv -> if inspect_fv fv = self then mk_e_app f [pack (Tv_Var bv)] else let f = mk (cur_module () @ ["print_" ^ (String.concat "_" (inspect_fv fv))]) in mk_e_app f [pack (Tv_Var bv)] | _ -> mk_stringlit "?" let mk_printer_type (t : term) : Tac term = let b = fresh_binder_named "arg" t in let str = pack (Tv_FVar (pack_fv string_lid)) in let c = pack_comp (C_Total str) in pack (Tv_Arrow b c) (* This tactics generates the entire let rec at once and * then uses exact. We could do something better. *) let mk_printer_fun (dom : term) : Tac term = set_guard_policy SMT; let e = top_env () in (* Recursive binding *) let ff = fresh_namedv_named "ff_rec" in let ffty = mk_printer_type dom in let fftm = pack (Tv_Var ff) in let x = fresh_binder_named "v" dom in let xt_ns = match inspect dom with | Tv_FVar fv -> (inspect_fv fv) | _ -> fail "not a qname type?" in let se = match lookup_typ e xt_ns with | None -> fail "Type not found..?" | Some se -> se in match inspect_sigelt se with | Sg_Let _ -> fail "cannot create printer for let" | Sg_Inductive {params=bs; typ=y; ctors} -> let br1 ctor : Tac branch = let (name, t) = ctor in let pn = String.concat "." name in let t_args, _ = collect_arr t in let bv_ty_pats = TU.map (fun ti -> let bv = fresh_namedv_named "a" in ((bv, ti), (Pat_Var {v=bv; sort=seal ti}, false))) t_args in let bvs, pats = List.Tot.split bv_ty_pats in let head = pack (Tv_Const (C_String pn)) in let bod = mk_concat (mk_stringlit " ") (head :: TU.map (mk_print_bv xt_ns fftm) bvs) in let bod = match t_args with | [] -> bod | _ -> paren bod in (Pat_Cons {head=pack_fv name; univs=None; subpats=pats}, bod) in let branches = TU.map br1 ctors in let xi = fresh_binder_named "v_inner" dom in // Generate the match on the internal argument let m = pack (Tv_Match (pack (Tv_Var (binder_to_namedv xi))) None branches) in (* debug ("m = " ^ term_to_string m); *) // Wrap it into an internal function let f = pack (Tv_Abs xi m) in (* debug ("f = " ^ term_to_string f); *) // Wrap it in a let rec; basically: // let rec ff = fun t -> match t with { .... } in ff x let ff_bnd : binder = { namedv_to_simple_binder ff with sort = ffty } in let xtm = pack (Tv_Var (binder_to_namedv x)) in let b = pack (Tv_Let true [] ff_bnd f (mk_e_app fftm [xtm])) in (* print ("b = " ^ term_to_string b); *) // Wrap it in a lambda taking the initial argument let tm = pack (Tv_Abs x b) in (* debug ("tm = " ^ term_to_string tm); *) tm | _ -> fail "type not found?"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.String.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Printers.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Util", "short_module": "TU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2.Derived", "short_module": "TD" }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": 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: (_: 'a -> 'a) -> l: Prims.list 'a -> Prims.list 'a
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Prims.Nil", "Prims.Cons", "Printers.maplast" ]
[ "recursion" ]
false
false
false
true
false
let rec maplast (f: ('a -> 'a)) (l: list 'a) : list 'a =
match l with | [] -> [] | [x] -> [f x] | x :: xs -> x :: (maplast f xs)
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.new_ffdhe_precomp_p
val new_ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p:ffdhe_precomp_p_st t a len ke -> new_ffdhe_precomp_p_st t a len ke
val new_ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p:ffdhe_precomp_p_st t a len ke -> new_ffdhe_precomp_p_st t a len ke
let new_ffdhe_precomp_p #t a len ke ffdhe_precomp_p r = let h0 = ST.get () in let nLen = blocks len (size (numbytes t)) in assert (v (nLen +! nLen) > 0); let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t #SEC 0) (nLen +! nLen) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == nLen +! nLen); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == v nLen + v nLen); let res: lbignum t (nLen +! nLen) = res in ffdhe_precomp_p res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 208, "start_col": 0, "start_line": 191 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s)) let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) inline_for_extraction noextract let ffdhe_bn_from_g_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = g_n:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a))) inline_for_extraction noextract val ffdhe_bn_from_g: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ffdhe_bn_from_g_st t a len let ffdhe_bn_from_g #t a len g_n = recall_contents ffdhe_g2 S.ffdhe_g2; [@inline_let] let nLen = blocks len (size (numbytes t)) in push_frame (); let g = create 1ul (u8 0) in mapT 1ul g secret ffdhe_g2; BSeq.nat_from_intseq_be_public_to_secret 1 S.ffdhe_g2; let h0 = ST.get () in update_sub_f h0 g_n 0ul 1ul (fun h -> SB.bn_from_bytes_be 1 (as_seq h0 g)) (fun _ -> BN.bn_from_bytes_be 1ul g (sub g_n 0ul 1ul)); let h1 = ST.get () in SD.bn_eval_update_sub #t 1 (SB.bn_from_bytes_be 1 (as_seq h0 g)) (v nLen); assert (bn_v h1 g_n == SD.bn_v (SB.bn_from_bytes_be #t 1 (as_seq h0 g))); SB.bn_from_bytes_be_lemma #t 1 (as_seq h0 g); assert (bn_v h1 g_n == BSeq.nat_from_bytes_be (as_seq h0 g)); pop_frame () inline_for_extraction noextract let ffdhe_precomp_inv (#t:limb_t) (#len:size_nat{0 < len /\ len + len <= max_size_t}) (a:S.ffdhe_alg) (p_r2_n:SD.lbignum t (len + len)) = let p_n = LSeq.sub p_r2_n 0 len in let r2_n = LSeq.sub p_r2_n len len in SD.bn_v p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ 0 < SD.bn_v p_n /\ SD.bn_v r2_n == pow2 (2 * bits t * len) % SD.bn_v p_n inline_for_extraction noextract let ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> Stack unit (requires fun h -> live h p_r2_n /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 _ h1 -> modifies (loc p_r2_n) h0 h1 /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 p_r2_n)) inline_for_extraction noextract val ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p_st t a len ke let ffdhe_precomp_p #t a len ke p_r2_n = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n = sub p_r2_n 0ul nLen in let r2_n = sub p_r2_n nLen nLen in let p_s = create len (u8 0) in ffdhe_p_to_ps a p_s; let h0 = ST.get () in BN.bn_from_bytes_be len p_s p_n; let h1 = ST.get () in SB.bn_from_bytes_be_lemma #t (v len) (as_seq h0 p_s); assert (bn_v h1 p_n == BSeq.nat_from_bytes_be (as_seq h0 p_s)); S.ffdhe_p_lemma a; Lemmas.ffdhe_p_bits_lemma a; ke.BE.precompr2 (8ul *! len -! 1ul) p_n r2_n; SM.bn_precomp_r2_mod_n_lemma (8 * v len - 1) (as_seq h1 p_n); pop_frame () inline_for_extraction noextract let new_ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in r:HS.rid -> ST (B.buffer (limb t)) (requires fun h -> ST.is_eternal_region r /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( B.len res == nLen +! nLen /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 (res <: lbignum t (nLen +! nLen))))) inline_for_extraction noextract val new_ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p:ffdhe_precomp_p_st t a len ke -> new_ffdhe_precomp_p_st t a len ke
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> ffdhe_precomp_p: Hacl.Impl.FFDHE.ffdhe_precomp_p_st t a len ke -> Hacl.Impl.FFDHE.new_ffdhe_precomp_p_st t a len ke
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Spec.FFDHE.ffdhe_alg", "Hacl.Impl.FFDHE.size_pos", "Hacl.Bignum.Exponentiation.exp", "Hacl.Impl.FFDHE.ffdhe_precomp_p_st", "FStar.Monotonic.HyperHeap.rid", "LowStar.Buffer.buffer", "Hacl.Bignum.Definitions.limb", "Prims.bool", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "LowStar.Monotonic.Buffer.loc_none", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.add", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims._assert", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.Buffer.buffer_t", "Lib.Buffer.MUT", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "Lib.IntTypes.op_Plus_Bang", "LowStar.Monotonic.Buffer.is_null", "LowStar.Monotonic.Buffer.mbuffer", "Prims.l_imp", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "Prims.l_and", "Prims.nat", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.freeable", "LowStar.Monotonic.Buffer.mmalloc_partial", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "LowStar.Monotonic.Buffer.lmbuffer_or_null", "Prims.op_GreaterThan", "Lib.IntTypes.int_t", "Prims.l_or", "Lib.IntTypes.range", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_Multiply", "Lib.IntTypes.mk_int", "Lib.IntTypes.numbytes", "Hacl.Spec.Bignum.Definitions.blocks", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size" ]
[]
false
false
false
false
false
let new_ffdhe_precomp_p #t a len ke ffdhe_precomp_p r =
let h0 = ST.get () in let nLen = blocks len (size (numbytes t)) in assert (v (nLen +! nLen) > 0); let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t #SEC 0) (nLen +! nLen) in if B.is_null res then res else let h1 = ST.get () in (let open B in modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == nLen +! nLen); let res:Lib.Buffer.buffer (limb t) = res in assert (B.length res == v nLen + v nLen); let res:lbignum t (nLen +! nLen) = res in ffdhe_precomp_p res; let h2 = ST.get () in (let open B in modifies_only_not_unused_in loc_none h0 h2); res
false
TwoLockQueue.fst
TwoLockQueue.elim_pure
val elim_pure: #p: prop -> #u: _ -> Prims.unit -> SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p)
val elim_pure: #p: prop -> #u: _ -> Prims.unit -> SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p)
let elim_pure (#p:prop) #u () : SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) = let _ = Steel.Effect.Atomic.elim_pure p in ()
{ "file_name": "share/steel/examples/steel/TwoLockQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 65, "start_col": 0, "start_line": 60 }
module TwoLockQueue open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock module L = FStar.List.Tot module U = Steel.Utils module Q = Queue /// This module provides an implementation of Michael and Scott's two lock queue, using the /// abstract interface for queues provided in Queue.fsti. /// This implementation allows an enqueue and a dequeue operation to safely operate in parallel. /// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation, /// ensuring that at most one enqueue (resp. dequeue) is happening at any time /// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue #push-options "--ide_id_info_off" /// Adding the definition of the vprop equivalence to the context, for proof purposes let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) = Classical.forall_intro_2 reveal_equiv (* Some wrappers to reduce clutter in the code *) [@@__reduce__] let full = full_perm [@@__reduce__] let half = half_perm full (* Wrappers around fst and snd to avoid overnormalization. TODO: The frame inference tactic should not normalize fst and snd *) let fst x = fst x let snd x = snd x (* Some wrappers around Steel functions which are easier to use inside this module *) let ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1}) (x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r p x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1) = let _ = ghost_gather_pt #a #u #p0 #p1 r in () let rewrite #u (p q:vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) = rewrite_slprop p q (fun _ -> reveal_equiv p q)
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Queue.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "TwoLockQueue.fst" }
[ { "abbrev": true, "full_module": "Queue", "short_module": "Q" }, { "abbrev": true, "full_module": "Steel.Utils", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Prims.prop", "Steel.Memory.inames", "Prims.unit", "Steel.Effect.Atomic.elim_pure", "Steel.Effect.Common.pure", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
false
true
false
false
false
let elim_pure (#p: prop) #u () : SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) =
let _ = Steel.Effect.Atomic.elim_pure p in ()
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.ffdhe_secret_to_public_precomp_st
val ffdhe_secret_to_public_precomp_st : t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
let ffdhe_secret_to_public_precomp_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> sk:lbuffer uint8 len -> pk:lbuffer uint8 len -> Stack unit (requires fun h -> live h sk /\ live h pk /\ live h p_r2_n /\ disjoint sk pk /\ disjoint sk p_r2_n /\ disjoint pk p_r2_n /\ v len == S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen /\ 1 < Lib.ByteSequence.nat_from_bytes_be (as_seq h sk) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h p_r2_n)) (ensures fun h0 _ h1 -> modifies (loc pk) h0 h1 /\ as_seq h1 pk == S.ffdhe_secret_to_public a (as_seq h0 sk))
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 283, "start_col": 0, "start_line": 269 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s)) let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) inline_for_extraction noextract let ffdhe_bn_from_g_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = g_n:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a))) inline_for_extraction noextract val ffdhe_bn_from_g: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ffdhe_bn_from_g_st t a len let ffdhe_bn_from_g #t a len g_n = recall_contents ffdhe_g2 S.ffdhe_g2; [@inline_let] let nLen = blocks len (size (numbytes t)) in push_frame (); let g = create 1ul (u8 0) in mapT 1ul g secret ffdhe_g2; BSeq.nat_from_intseq_be_public_to_secret 1 S.ffdhe_g2; let h0 = ST.get () in update_sub_f h0 g_n 0ul 1ul (fun h -> SB.bn_from_bytes_be 1 (as_seq h0 g)) (fun _ -> BN.bn_from_bytes_be 1ul g (sub g_n 0ul 1ul)); let h1 = ST.get () in SD.bn_eval_update_sub #t 1 (SB.bn_from_bytes_be 1 (as_seq h0 g)) (v nLen); assert (bn_v h1 g_n == SD.bn_v (SB.bn_from_bytes_be #t 1 (as_seq h0 g))); SB.bn_from_bytes_be_lemma #t 1 (as_seq h0 g); assert (bn_v h1 g_n == BSeq.nat_from_bytes_be (as_seq h0 g)); pop_frame () inline_for_extraction noextract let ffdhe_precomp_inv (#t:limb_t) (#len:size_nat{0 < len /\ len + len <= max_size_t}) (a:S.ffdhe_alg) (p_r2_n:SD.lbignum t (len + len)) = let p_n = LSeq.sub p_r2_n 0 len in let r2_n = LSeq.sub p_r2_n len len in SD.bn_v p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ 0 < SD.bn_v p_n /\ SD.bn_v r2_n == pow2 (2 * bits t * len) % SD.bn_v p_n inline_for_extraction noextract let ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> Stack unit (requires fun h -> live h p_r2_n /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 _ h1 -> modifies (loc p_r2_n) h0 h1 /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 p_r2_n)) inline_for_extraction noextract val ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p_st t a len ke let ffdhe_precomp_p #t a len ke p_r2_n = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n = sub p_r2_n 0ul nLen in let r2_n = sub p_r2_n nLen nLen in let p_s = create len (u8 0) in ffdhe_p_to_ps a p_s; let h0 = ST.get () in BN.bn_from_bytes_be len p_s p_n; let h1 = ST.get () in SB.bn_from_bytes_be_lemma #t (v len) (as_seq h0 p_s); assert (bn_v h1 p_n == BSeq.nat_from_bytes_be (as_seq h0 p_s)); S.ffdhe_p_lemma a; Lemmas.ffdhe_p_bits_lemma a; ke.BE.precompr2 (8ul *! len -! 1ul) p_n r2_n; SM.bn_precomp_r2_mod_n_lemma (8 * v len - 1) (as_seq h1 p_n); pop_frame () inline_for_extraction noextract let new_ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in r:HS.rid -> ST (B.buffer (limb t)) (requires fun h -> ST.is_eternal_region r /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( B.len res == nLen +! nLen /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 (res <: lbignum t (nLen +! nLen))))) inline_for_extraction noextract val new_ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p:ffdhe_precomp_p_st t a len ke -> new_ffdhe_precomp_p_st t a len ke let new_ffdhe_precomp_p #t a len ke ffdhe_precomp_p r = let h0 = ST.get () in let nLen = blocks len (size (numbytes t)) in assert (v (nLen +! nLen) > 0); let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t #SEC 0) (nLen +! nLen) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == nLen +! nLen); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == v nLen + v nLen); let res: lbignum t (nLen +! nLen) = res in ffdhe_precomp_p res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let ffdhe_compute_exp_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> sk_n:lbignum t nLen -> b_n:lbignum t nLen -> res:lbuffer uint8 len -> Stack unit (requires fun h -> live h p_r2_n /\ live h sk_n /\ live h b_n /\ live h res /\ disjoint p_r2_n res /\ disjoint sk_n res /\ disjoint b_n res /\ disjoint p_r2_n b_n /\ disjoint p_r2_n sk_n /\ v len == S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h p_r2_n) /\ bn_v h b_n < bn_v h (gsub p_r2_n 0ul nLen) - 1 /\ 1 < bn_v h sk_n) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ (S.ffdhe_p_lemma a; let res_n = Lib.NatMod.pow_mod #(bn_v h0 (gsub p_r2_n 0ul nLen)) (bn_v h0 b_n) (bn_v h0 sk_n) in as_seq h1 res == BSeq.nat_to_bytes_be (v len) res_n)) #push-options "--z3rlimit 100" inline_for_extraction noextract val ffdhe_compute_exp: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_compute_exp_st t a len ke let ffdhe_compute_exp #t a len ke p_r2_n sk_n b_n res = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n = sub p_r2_n 0ul nLen in let r2_n = sub p_r2_n nLen nLen in let res_n = create nLen (uint #t #SEC 0) in let h1 = ST.get () in S.ffdhe_p_lemma a; assert_norm (pow2 4 = 16); assert_norm (pow2 10 = 1024); Math.Lemmas.pow2_plus 4 10; Math.Lemmas.pow2_lt_compat 32 14; SD.bn_eval_bound #t (as_seq h1 sk_n) (v nLen); BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_ct_precomp p_n r2_n b_n (size (bits t) *! nLen) sk_n res_n; //b_n ^ sk_n % p_n let h2 = ST.get () in BN.bn_to_bytes_be len res_n res; SB.bn_to_bytes_be_lemma (v len) (as_seq h2 res_n); pop_frame () #pop-options
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Spec.FFDHE.ffdhe_alg", "Hacl.Impl.FFDHE.size_pos", "Hacl.Bignum.Exponentiation.exp", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.IntTypes.v", "Spec.FFDHE.ffdhe_len", "Lib.IntTypes.size_t", "FStar.Mul.op_Star", "Lib.IntTypes.size", "Lib.IntTypes.numbytes", "Hacl.Spec.Bignum.Definitions.blocks", "Prims.op_LessThan", "Lib.IntTypes.bits", "Hacl.Bignum.__proj__Mkbn__item__len", "Hacl.Bignum.Exponentiation.__proj__Mkexp__item__bn", "Lib.ByteSequence.nat_from_bytes_be", "Lib.IntTypes.SEC", "Lib.Buffer.as_seq", "Hacl.Impl.FFDHE.ffdhe_precomp_inv", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Lib.Sequence.seq", "Prims.nat", "FStar.Seq.Base.length", "Spec.FFDHE.ffdhe_secret_to_public", "Lib.IntTypes.int_t", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_Multiply", "Lib.IntTypes.mk_int", "Hacl.Bignum.Definitions.blocks" ]
[]
false
false
false
false
true
let ffdhe_secret_to_public_precomp_st (t: limb_t) (a: S.ffdhe_alg) (len: size_pos) (ke: BE.exp t) =
let nLen = blocks len (size (numbytes t)) in p_r2_n: lbignum t (nLen +! nLen) -> sk: lbuffer uint8 len -> pk: lbuffer uint8 len -> Stack unit (requires fun h -> live h sk /\ live h pk /\ live h p_r2_n /\ disjoint sk pk /\ disjoint sk p_r2_n /\ disjoint pk p_r2_n /\ v len == S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen /\ 1 < Lib.ByteSequence.nat_from_bytes_be (as_seq h sk) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h p_r2_n)) (ensures fun h0 _ h1 -> modifies (loc pk) h0 h1 /\ as_seq h1 pk == S.ffdhe_secret_to_public a (as_seq h0 sk))
false
Vale.AES.X64.AESopt.fsti
Vale.AES.X64.AESopt.six_of
val six_of : a: Type0 -> Type0
let six_of (a:Type0) = a & a & a & a & a & a
{ "file_name": "obj/Vale.AES.X64.AESopt.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 62, "start_col": 0, "start_line": 62 }
module Vale.AES.X64.AESopt open FStar.Mul open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.AES.AES_helpers //open Vale.Poly1305.Math // For lemma_poly_bits64() open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.Arch.TypesNative open Vale.X64.CPU_Features_s open Vale.Math.Poly2_s open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.X64.PolyOps open Vale.AES.X64.AESopt2 open Vale.AES.X64.AESGCM_expected_code open Vale.Transformers.Transform open FStar.Mul let aes_reqs0 (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ alg = AES_128 /\ //(alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ buffer128_as_seq heap0 keys_b == round_keys let aes_reqs_offset (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ avx_enabled /\ pclmulqdq_enabled /\ (alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ s128 heap0 keys_b == round_keys
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Transformers.Transform.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.AESopt2.fsti.checked", "Vale.AES.X64.AESGCM_expected_code.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_helpers.fsti.checked", "Vale.AES.AES_common_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AESopt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Transform", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM_expected_code", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple6" ]
[]
false
false
false
true
true
let six_of (a: Type0) =
a & a & a & a & a & a
false
Vale.AES.X64.AESopt.fsti
Vale.AES.X64.AESopt.quad32_6
val quad32_6 : Type0
let quad32_6 = six_of quad32
{ "file_name": "obj/Vale.AES.X64.AESopt.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 63, "start_col": 0, "start_line": 63 }
module Vale.AES.X64.AESopt open FStar.Mul open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.AES.AES_helpers //open Vale.Poly1305.Math // For lemma_poly_bits64() open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.Arch.TypesNative open Vale.X64.CPU_Features_s open Vale.Math.Poly2_s open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.X64.PolyOps open Vale.AES.X64.AESopt2 open Vale.AES.X64.AESGCM_expected_code open Vale.Transformers.Transform open FStar.Mul let aes_reqs0 (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ alg = AES_128 /\ //(alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ buffer128_as_seq heap0 keys_b == round_keys let aes_reqs_offset (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ avx_enabled /\ pclmulqdq_enabled /\ (alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ s128 heap0 keys_b == round_keys
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Transformers.Transform.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.AESopt2.fsti.checked", "Vale.AES.X64.AESGCM_expected_code.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_helpers.fsti.checked", "Vale.AES.AES_common_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AESopt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Transform", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM_expected_code", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.AES.X64.AESopt.six_of", "Vale.X64.Decls.quad32" ]
[]
false
false
false
true
true
let quad32_6 =
six_of quad32
false
Hacl.Impl.FFDHE.fst
Hacl.Impl.FFDHE.ffdhe_shared_secret_st
val ffdhe_shared_secret_st : t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
let ffdhe_shared_secret_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = sk:lbuffer uint8 len -> pk:lbuffer uint8 len -> ss:lbuffer uint8 len -> Stack (limb t) (requires fun h -> live h sk /\ live h pk /\ live h ss /\ disjoint sk pk /\ disjoint sk ss /\ disjoint pk ss /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == blocks len (size (numbytes t)) /\ 1 < Lib.ByteSequence.nat_from_bytes_be (as_seq h sk)) (ensures fun h0 m h1 -> modifies (loc ss) h0 h1 /\ (let ss_s = S.ffdhe_shared_secret a (as_seq h0 sk) (as_seq h0 pk) in if v m = v (ones t SEC) then Some? ss_s /\ as_seq h1 ss == Some?.v ss_s else None? ss_s))
{ "file_name": "code/ffdhe/Hacl.Impl.FFDHE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 93, "end_line": 460, "start_col": 0, "start_line": 446 }
module Hacl.Impl.FFDHE open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.FFDHE.Constants open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.FFDHE module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.FFDHE.Lemmas module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module SB = Hacl.Spec.Bignum module SM = Hacl.Spec.Bignum.Montgomery module SE = Hacl.Spec.Bignum.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let size_pos = x:size_t{v x > 0} [@CInline] let ffdhe_len (a:S.ffdhe_alg) : x:size_pos{v x = S.ffdhe_len a} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> 256ul | S.FFDHE3072 -> 384ul | S.FFDHE4096 -> 512ul | S.FFDHE6144 -> 768ul | S.FFDHE8192 -> 1024ul inline_for_extraction noextract let get_ffdhe_p (a:S.ffdhe_alg) :x:glbuffer pub_uint8 (ffdhe_len a) {witnessed x (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ recallable x} = allow_inversion S.ffdhe_alg; match a with | S.FFDHE2048 -> ffdhe_p2048 | S.FFDHE3072 -> ffdhe_p3072 | S.FFDHE4096 -> ffdhe_p4096 | S.FFDHE6144 -> ffdhe_p6144 | S.FFDHE8192 -> ffdhe_p8192 inline_for_extraction noextract val ffdhe_p_to_ps: a:S.ffdhe_alg -> p_s:lbuffer uint8 (ffdhe_len a) -> Stack unit (requires fun h -> live h p_s) (ensures fun h0 _ h1 -> modifies (loc p_s) h0 h1 /\ BSeq.nat_from_intseq_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) == BSeq.nat_from_intseq_be (as_seq h1 p_s)) let ffdhe_p_to_ps a p_s = let p = get_ffdhe_p a in recall_contents p (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)); let len = ffdhe_len a in mapT len p_s secret p; BSeq.nat_from_intseq_be_public_to_secret (v len) (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) inline_for_extraction noextract let ffdhe_bn_from_g_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = g_n:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h g_n /\ v len = S.ffdhe_len a /\ as_seq h g_n == LSeq.create (v (blocks len (size (numbytes t)))) (uint #t 0)) (ensures fun h0 _ h1 -> modifies (loc g_n) h0 h1 /\ bn_v h1 g_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_g (S.get_ffdhe_params a))) inline_for_extraction noextract val ffdhe_bn_from_g: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ffdhe_bn_from_g_st t a len let ffdhe_bn_from_g #t a len g_n = recall_contents ffdhe_g2 S.ffdhe_g2; [@inline_let] let nLen = blocks len (size (numbytes t)) in push_frame (); let g = create 1ul (u8 0) in mapT 1ul g secret ffdhe_g2; BSeq.nat_from_intseq_be_public_to_secret 1 S.ffdhe_g2; let h0 = ST.get () in update_sub_f h0 g_n 0ul 1ul (fun h -> SB.bn_from_bytes_be 1 (as_seq h0 g)) (fun _ -> BN.bn_from_bytes_be 1ul g (sub g_n 0ul 1ul)); let h1 = ST.get () in SD.bn_eval_update_sub #t 1 (SB.bn_from_bytes_be 1 (as_seq h0 g)) (v nLen); assert (bn_v h1 g_n == SD.bn_v (SB.bn_from_bytes_be #t 1 (as_seq h0 g))); SB.bn_from_bytes_be_lemma #t 1 (as_seq h0 g); assert (bn_v h1 g_n == BSeq.nat_from_bytes_be (as_seq h0 g)); pop_frame () inline_for_extraction noextract let ffdhe_precomp_inv (#t:limb_t) (#len:size_nat{0 < len /\ len + len <= max_size_t}) (a:S.ffdhe_alg) (p_r2_n:SD.lbignum t (len + len)) = let p_n = LSeq.sub p_r2_n 0 len in let r2_n = LSeq.sub p_r2_n len len in SD.bn_v p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a)) /\ 0 < SD.bn_v p_n /\ SD.bn_v r2_n == pow2 (2 * bits t * len) % SD.bn_v p_n inline_for_extraction noextract let ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> Stack unit (requires fun h -> live h p_r2_n /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 _ h1 -> modifies (loc p_r2_n) h0 h1 /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 p_r2_n)) inline_for_extraction noextract val ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p_st t a len ke let ffdhe_precomp_p #t a len ke p_r2_n = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n = sub p_r2_n 0ul nLen in let r2_n = sub p_r2_n nLen nLen in let p_s = create len (u8 0) in ffdhe_p_to_ps a p_s; let h0 = ST.get () in BN.bn_from_bytes_be len p_s p_n; let h1 = ST.get () in SB.bn_from_bytes_be_lemma #t (v len) (as_seq h0 p_s); assert (bn_v h1 p_n == BSeq.nat_from_bytes_be (as_seq h0 p_s)); S.ffdhe_p_lemma a; Lemmas.ffdhe_p_bits_lemma a; ke.BE.precompr2 (8ul *! len -! 1ul) p_n r2_n; SM.bn_precomp_r2_mod_n_lemma (8 * v len - 1) (as_seq h1 p_n); pop_frame () inline_for_extraction noextract let new_ffdhe_precomp_p_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in r:HS.rid -> ST (B.buffer (limb t)) (requires fun h -> ST.is_eternal_region r /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( B.len res == nLen +! nLen /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h1 (res <: lbignum t (nLen +! nLen))))) inline_for_extraction noextract val new_ffdhe_precomp_p: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_precomp_p:ffdhe_precomp_p_st t a len ke -> new_ffdhe_precomp_p_st t a len ke let new_ffdhe_precomp_p #t a len ke ffdhe_precomp_p r = let h0 = ST.get () in let nLen = blocks len (size (numbytes t)) in assert (v (nLen +! nLen) > 0); let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t #SEC 0) (nLen +! nLen) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == nLen +! nLen); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == v nLen + v nLen); let res: lbignum t (nLen +! nLen) = res in ffdhe_precomp_p res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let ffdhe_compute_exp_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> sk_n:lbignum t nLen -> b_n:lbignum t nLen -> res:lbuffer uint8 len -> Stack unit (requires fun h -> live h p_r2_n /\ live h sk_n /\ live h b_n /\ live h res /\ disjoint p_r2_n res /\ disjoint sk_n res /\ disjoint b_n res /\ disjoint p_r2_n b_n /\ disjoint p_r2_n sk_n /\ v len == S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h p_r2_n) /\ bn_v h b_n < bn_v h (gsub p_r2_n 0ul nLen) - 1 /\ 1 < bn_v h sk_n) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ (S.ffdhe_p_lemma a; let res_n = Lib.NatMod.pow_mod #(bn_v h0 (gsub p_r2_n 0ul nLen)) (bn_v h0 b_n) (bn_v h0 sk_n) in as_seq h1 res == BSeq.nat_to_bytes_be (v len) res_n)) #push-options "--z3rlimit 100" inline_for_extraction noextract val ffdhe_compute_exp: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_compute_exp_st t a len ke let ffdhe_compute_exp #t a len ke p_r2_n sk_n b_n res = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n = sub p_r2_n 0ul nLen in let r2_n = sub p_r2_n nLen nLen in let res_n = create nLen (uint #t #SEC 0) in let h1 = ST.get () in S.ffdhe_p_lemma a; assert_norm (pow2 4 = 16); assert_norm (pow2 10 = 1024); Math.Lemmas.pow2_plus 4 10; Math.Lemmas.pow2_lt_compat 32 14; SD.bn_eval_bound #t (as_seq h1 sk_n) (v nLen); BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_ct_precomp p_n r2_n b_n (size (bits t) *! nLen) sk_n res_n; //b_n ^ sk_n % p_n let h2 = ST.get () in BN.bn_to_bytes_be len res_n res; SB.bn_to_bytes_be_lemma (v len) (as_seq h2 res_n); pop_frame () #pop-options inline_for_extraction noextract let ffdhe_secret_to_public_precomp_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> sk:lbuffer uint8 len -> pk:lbuffer uint8 len -> Stack unit (requires fun h -> live h sk /\ live h pk /\ live h p_r2_n /\ disjoint sk pk /\ disjoint sk p_r2_n /\ disjoint pk p_r2_n /\ v len == S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen /\ 1 < Lib.ByteSequence.nat_from_bytes_be (as_seq h sk) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h p_r2_n)) (ensures fun h0 _ h1 -> modifies (loc pk) h0 h1 /\ as_seq h1 pk == S.ffdhe_secret_to_public a (as_seq h0 sk)) //TODO: pass sBits? inline_for_extraction noextract val ffdhe_secret_to_public_precomp: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_compute_exp:ffdhe_compute_exp_st t a len ke -> ffdhe_secret_to_public_precomp_st t a len ke let ffdhe_secret_to_public_precomp #t a len ke ffdhe_compute_exp p_r2_n sk pk = push_frame (); let nLen = blocks len (size (numbytes t)) in let g_n = create nLen (uint #t #SEC 0) in ffdhe_bn_from_g a len g_n; let sk_n = create nLen (uint #t #SEC 0) in let h0 = ST.get () in BN.bn_from_bytes_be len sk sk_n; SB.bn_from_bytes_be_lemma #t (v len) (as_seq h0 sk); S.ffdhe_g2_lemma (); S.ffdhe_p_lemma a; ffdhe_compute_exp p_r2_n sk_n g_n pk; pop_frame () inline_for_extraction noextract let ffdhe_secret_to_public_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = sk:lbuffer uint8 len -> pk:lbuffer uint8 len -> Stack unit (requires fun h -> live h sk /\ live h pk /\ disjoint sk pk /\ v len == S.ffdhe_len a /\ ke.BE.bn.BN.len == blocks len (size (numbytes t)) /\ 1 < Lib.ByteSequence.nat_from_bytes_be (as_seq h sk)) (ensures fun h0 _ h1 -> modifies (loc pk) h0 h1 /\ as_seq h1 pk == S.ffdhe_secret_to_public a (as_seq h0 sk)) //TODO: pass sBits? inline_for_extraction noextract val ffdhe_secret_to_public: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_secret_to_public_precomp:ffdhe_secret_to_public_precomp_st t a len ke -> ffdhe_precomp_p:ffdhe_precomp_p_st t a len ke -> ffdhe_secret_to_public_st t a len ke let ffdhe_secret_to_public #t a len ke ffdhe_secret_to_public_precomp ffdhe_precomp_p sk pk = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_r2_n = create (nLen +! nLen) (uint #t #SEC 0) in ffdhe_precomp_p p_r2_n; ffdhe_secret_to_public_precomp p_r2_n sk pk; pop_frame () inline_for_extraction noextract let ffdhe_check_pk_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) = let nLen = blocks len (size (numbytes t)) in pk_n:lbignum t nLen -> p_n:lbignum t nLen -> Stack (limb t) (requires fun h -> live h pk_n /\ live h p_n /\ disjoint pk_n p_n /\ v len = S.ffdhe_len a /\ bn_v h p_n == BSeq.nat_from_bytes_be (S.Mk_ffdhe_params?.ffdhe_p (S.get_ffdhe_params a))) (ensures fun h0 m h1 -> modifies0 h0 h1 /\ v m == (if (1 < bn_v h0 pk_n && bn_v h0 pk_n < bn_v h0 p_n - 1) then v (ones t SEC) else 0)) inline_for_extraction noextract val ffdhe_check_pk: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ffdhe_check_pk_st t a len let ffdhe_check_pk #t a len pk_n p_n = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n1 = create nLen (uint #t #SEC 0) in let h0 = ST.get () in let c = BN.bn_sub1 nLen p_n (uint #t 1) p_n1 in SB.bn_sub1_lemma (as_seq h0 p_n) (uint #t 1); let h1 = ST.get () in S.ffdhe_p_lemma a; SD.bn_eval_bound (as_seq h1 p_n1) (v nLen); assert (bn_v h1 p_n1 == bn_v h0 p_n - 1); let m0 = BN.bn_gt_pow2_mask nLen pk_n 0ul in SB.bn_gt_pow2_mask_lemma (as_seq h1 pk_n) 0; assert_norm (pow2 0 = 1); assert (if v m0 = 0 then 1 >= bn_v h1 pk_n else 1 < bn_v h1 pk_n); let m1 = BN.bn_lt_mask nLen pk_n p_n1 in SB.bn_lt_mask_lemma (as_seq h1 pk_n) (as_seq h1 p_n1); assert (if v m1 = 0 then bn_v h1 pk_n >= bn_v h1 p_n1 else bn_v h1 pk_n < bn_v h1 p_n1); let m = m0 &. m1 in logand_lemma m0 m1; pop_frame (); m inline_for_extraction noextract let ffdhe_shared_secret_precomp_st (t:limb_t) (a:S.ffdhe_alg) (len:size_pos) (ke:BE.exp t) = let nLen = blocks len (size (numbytes t)) in p_r2_n:lbignum t (nLen +! nLen) -> sk:lbuffer uint8 len -> pk:lbuffer uint8 len -> ss:lbuffer uint8 len -> Stack (limb t) (requires fun h -> live h sk /\ live h pk /\ live h ss /\ live h p_r2_n /\ disjoint sk pk /\ disjoint sk ss /\ disjoint pk ss /\ disjoint p_r2_n ss /\ disjoint p_r2_n pk /\ disjoint p_r2_n sk /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == nLen /\ 1 < Lib.ByteSequence.nat_from_bytes_be (as_seq h sk) /\ ffdhe_precomp_inv #t #(v nLen) a (as_seq h p_r2_n)) (ensures fun h0 m h1 -> modifies (loc ss) h0 h1 /\ (let ss_s = S.ffdhe_shared_secret a (as_seq h0 sk) (as_seq h0 pk) in if v m = v (ones t SEC) then Some? ss_s /\ as_seq h1 ss == Some?.v ss_s else None? ss_s)) inline_for_extraction noextract val ffdhe_shared_secret_precomp: #t:limb_t -> a:S.ffdhe_alg -> len:size_pos -> ke:BE.exp t -> ffdhe_check_pk:ffdhe_check_pk_st t a len -> ffdhe_compute_exp:ffdhe_compute_exp_st t a len ke -> ffdhe_shared_secret_precomp_st t a len ke let ffdhe_shared_secret_precomp #t a len ke ffdhe_check_pk ffdhe_compute_exp p_r2_n sk pk ss = push_frame (); let nLen = blocks len (size (numbytes t)) in let p_n = sub p_r2_n 0ul nLen in let sk_n = create nLen (uint #t #SEC 0) in let pk_n = create nLen (uint #t #SEC 0) in let h0 = ST.get () in BN.bn_from_bytes_be len sk sk_n; BN.bn_from_bytes_be len pk pk_n; SB.bn_from_bytes_be_lemma #t (v len) (as_seq h0 sk); SB.bn_from_bytes_be_lemma #t (v len) (as_seq h0 pk); S.ffdhe_p_lemma a; let m = ffdhe_check_pk pk_n p_n in if Hacl.Bignum.Base.unsafe_bool_of_limb m then ffdhe_compute_exp p_r2_n sk_n pk_n ss; pop_frame (); m
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.FFDHE.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "Hacl.Impl.FFDHE.Constants.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.FFDHE.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.FFDHE.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.FFDHE", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.FFDHE.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> a: Spec.FFDHE.ffdhe_alg -> len: Hacl.Impl.FFDHE.size_pos -> ke: Hacl.Bignum.Exponentiation.exp t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Spec.FFDHE.ffdhe_alg", "Hacl.Impl.FFDHE.size_pos", "Hacl.Bignum.Exponentiation.exp", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Lib.IntTypes.U32", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Spec.FFDHE.ffdhe_len", "Prims.eq2", "Lib.IntTypes.size_t", "FStar.Mul.op_Star", "Lib.IntTypes.size", "Lib.IntTypes.numbytes", "Hacl.Spec.Bignum.Definitions.blocks", "Prims.op_LessThan", "Lib.IntTypes.bits", "Hacl.Bignum.__proj__Mkbn__item__len", "Hacl.Bignum.Exponentiation.__proj__Mkexp__item__bn", "Hacl.Bignum.Definitions.blocks", "Lib.ByteSequence.nat_from_bytes_be", "Lib.IntTypes.SEC", "Lib.Buffer.as_seq", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Lib.IntTypes.range_t", "Lib.IntTypes.ones", "FStar.Pervasives.Native.uu___is_Some", "Lib.Sequence.lseq", "Lib.Sequence.seq", "Prims.nat", "FStar.Seq.Base.length", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.bool", "FStar.Pervasives.Native.uu___is_None", "Prims.logical", "FStar.Pervasives.Native.option", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Spec.FFDHE.ffdhe_shared_secret" ]
[]
false
false
false
false
true
let ffdhe_shared_secret_st (t: limb_t) (a: S.ffdhe_alg) (len: size_pos) (ke: BE.exp t) =
sk: lbuffer uint8 len -> pk: lbuffer uint8 len -> ss: lbuffer uint8 len -> Stack (limb t) (requires fun h -> live h sk /\ live h pk /\ live h ss /\ disjoint sk pk /\ disjoint sk ss /\ disjoint pk ss /\ v len = S.ffdhe_len a /\ ke.BE.bn.BN.len == blocks len (size (numbytes t)) /\ 1 < Lib.ByteSequence.nat_from_bytes_be (as_seq h sk)) (ensures fun h0 m h1 -> modifies (loc ss) h0 h1 /\ (let ss_s = S.ffdhe_shared_secret a (as_seq h0 sk) (as_seq h0 pk) in if v m = v (ones t SEC) then Some? ss_s /\ as_seq h1 ss == Some?.v ss_s else None? ss_s) )
false
Vale.AES.X64.AESopt.fsti
Vale.AES.X64.AESopt.map_six_of
val map_six_of (#a #b: Type0) (x: six_of a) (f: (a -> GTot b)) : GTot (six_of b)
val map_six_of (#a #b: Type0) (x: six_of a) (f: (a -> GTot b)) : GTot (six_of b)
let map_six_of (#a #b:Type0) (x:six_of a) (f:a -> GTot b) : GTot (six_of b) = let (x0, x1, x2, x3, x4, x5) = x in (f x0, f x1, f x2, f x3, f x4, f x5)
{ "file_name": "obj/Vale.AES.X64.AESopt.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 69, "start_col": 7, "start_line": 67 }
module Vale.AES.X64.AESopt open FStar.Mul open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.AES.AES_helpers //open Vale.Poly1305.Math // For lemma_poly_bits64() open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.Arch.TypesNative open Vale.X64.CPU_Features_s open Vale.Math.Poly2_s open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.X64.PolyOps open Vale.AES.X64.AESopt2 open Vale.AES.X64.AESGCM_expected_code open Vale.Transformers.Transform open FStar.Mul let aes_reqs0 (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ alg = AES_128 /\ //(alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ buffer128_as_seq heap0 keys_b == round_keys let aes_reqs_offset (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ avx_enabled /\ pclmulqdq_enabled /\ (alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ s128 heap0 keys_b == round_keys let six_of (a:Type0) = a & a & a & a & a & a let quad32_6 = six_of quad32 unfold let make_six_of (#a:Type0) (f:(n:nat{n < 6}) -> GTot a) : GTot (six_of a) =
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Transformers.Transform.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.AESopt2.fsti.checked", "Vale.AES.X64.AESGCM_expected_code.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_helpers.fsti.checked", "Vale.AES.AES_common_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AESopt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Transform", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM_expected_code", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.AES.X64.AESopt.six_of a -> f: (_: a -> Prims.GTot b) -> Prims.GTot (Vale.AES.X64.AESopt.six_of b)
Prims.GTot
[ "sometrivial" ]
[]
[ "Vale.AES.X64.AESopt.six_of", "FStar.Pervasives.Native.Mktuple6" ]
[]
false
false
false
false
false
let map_six_of (#a #b: Type0) (x: six_of a) (f: (a -> GTot b)) : GTot (six_of b) =
let x0, x1, x2, x3, x4, x5 = x in (f x0, f x1, f x2, f x3, f x4, f x5)
false
Vale.AES.X64.AESopt.fsti
Vale.AES.X64.AESopt.make_six_of
val make_six_of (#a: Type0) (f: (n: nat{n < 6} -> GTot a)) : GTot (six_of a)
val make_six_of (#a: Type0) (f: (n: nat{n < 6} -> GTot a)) : GTot (six_of a)
let make_six_of (#a:Type0) (f:(n:nat{n < 6}) -> GTot a) : GTot (six_of a) = (f 0, f 1, f 2, f 3, f 4, f 5)
{ "file_name": "obj/Vale.AES.X64.AESopt.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 66, "start_col": 7, "start_line": 65 }
module Vale.AES.X64.AESopt open FStar.Mul open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.AES.AES_helpers //open Vale.Poly1305.Math // For lemma_poly_bits64() open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.Arch.TypesNative open Vale.X64.CPU_Features_s open Vale.Math.Poly2_s open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.X64.PolyOps open Vale.AES.X64.AESopt2 open Vale.AES.X64.AESGCM_expected_code open Vale.Transformers.Transform open FStar.Mul let aes_reqs0 (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ alg = AES_128 /\ //(alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ buffer128_as_seq heap0 keys_b == round_keys let aes_reqs_offset (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ avx_enabled /\ pclmulqdq_enabled /\ (alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ s128 heap0 keys_b == round_keys let six_of (a:Type0) = a & a & a & a & a & a let quad32_6 = six_of quad32
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Transformers.Transform.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.AESopt2.fsti.checked", "Vale.AES.X64.AESGCM_expected_code.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_helpers.fsti.checked", "Vale.AES.AES_common_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AESopt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Transform", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM_expected_code", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (n: Prims.nat{n < 6} -> Prims.GTot a) -> Prims.GTot (Vale.AES.X64.AESopt.six_of a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Pervasives.Native.Mktuple6", "Vale.AES.X64.AESopt.six_of" ]
[]
false
false
false
false
false
let make_six_of (#a: Type0) (f: (n: nat{n < 6} -> GTot a)) : GTot (six_of a) =
(f 0, f 1, f 2, f 3, f 4, f 5)
false
Vale.AES.X64.AESopt.fsti
Vale.AES.X64.AESopt.rounds_opaque_6
val rounds_opaque_6 (init: quad32_6) (round_keys: seq quad32) (rnd: nat{rnd < length round_keys}) : GTot quad32_6
val rounds_opaque_6 (init: quad32_6) (round_keys: seq quad32) (rnd: nat{rnd < length round_keys}) : GTot quad32_6
let rounds_opaque_6 (init:quad32_6) (round_keys:seq quad32) (rnd:nat{rnd < length round_keys}) : GTot quad32_6 = map_six_of init (fun x -> eval_rounds x round_keys rnd)
{ "file_name": "obj/Vale.AES.X64.AESopt.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 76, "start_col": 0, "start_line": 75 }
module Vale.AES.X64.AESopt open FStar.Mul open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.AES.AES_helpers //open Vale.Poly1305.Math // For lemma_poly_bits64() open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.Arch.TypesNative open Vale.X64.CPU_Features_s open Vale.Math.Poly2_s open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.X64.PolyOps open Vale.AES.X64.AESopt2 open Vale.AES.X64.AESGCM_expected_code open Vale.Transformers.Transform open FStar.Mul let aes_reqs0 (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ alg = AES_128 /\ //(alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ buffer128_as_seq heap0 keys_b == round_keys let aes_reqs_offset (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ avx_enabled /\ pclmulqdq_enabled /\ (alg = AES_128 || alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrsOffset128 heap0 key_ptr keys_b 8 (nr alg + 1 - 8) layout Secret /\ s128 heap0 keys_b == round_keys let six_of (a:Type0) = a & a & a & a & a & a let quad32_6 = six_of quad32 unfold let make_six_of (#a:Type0) (f:(n:nat{n < 6}) -> GTot a) : GTot (six_of a) = (f 0, f 1, f 2, f 3, f 4, f 5) unfold let map_six_of (#a #b:Type0) (x:six_of a) (f:a -> GTot b) : GTot (six_of b) = let (x0, x1, x2, x3, x4, x5) = x in (f x0, f x1, f x2, f x3, f x4, f x5) unfold let map2_six_of (#a #b #c:Type0) (x:six_of a) (y:six_of b) (f:a -> b -> GTot c) : GTot (six_of c) = let (x0, x1, x2, x3, x4, x5) = x in let (y0, y1, y2, y3, y4, y5) = y in (f x0 y0, f x1 y1, f x2 y2, f x3 y3, f x4 y4, f x5 y5)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Transformers.Transform.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.AESopt2.fsti.checked", "Vale.AES.X64.AESGCM_expected_code.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_helpers.fsti.checked", "Vale.AES.AES_common_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AESopt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Transform", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM_expected_code", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
init: Vale.AES.X64.AESopt.quad32_6 -> round_keys: FStar.Seq.Base.seq Vale.X64.Decls.quad32 -> rnd: Prims.nat{rnd < FStar.Seq.Base.length round_keys} -> Prims.GTot Vale.AES.X64.AESopt.quad32_6
Prims.GTot
[ "sometrivial" ]
[]
[ "Vale.AES.X64.AESopt.quad32_6", "FStar.Seq.Base.seq", "Vale.X64.Decls.quad32", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.AES.X64.AESopt.map_six_of", "Vale.Def.Types_s.quad32", "Vale.AES.AES_s.eval_rounds" ]
[]
false
false
false
false
false
let rounds_opaque_6 (init: quad32_6) (round_keys: seq quad32) (rnd: nat{rnd < length round_keys}) : GTot quad32_6 =
map_six_of init (fun x -> eval_rounds x round_keys rnd)
false