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
DoublyLinkedList.fst
DoublyLinkedList.piece_remains_valid_f
val piece_remains_valid_f (#t: Type) (h0 h1: heap) (p: piece t) : Lemma (requires ((piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1) /\ (h1 `contains` p.ptail) /\ (p.ptail @ h0).blink == (p.ptail @ h1).blink)) (ensures (piece_valid h1 p) /\ (p.phead @ h0).blink == (p.phead @ h1).blink)
val piece_remains_valid_f (#t: Type) (h0 h1: heap) (p: piece t) : Lemma (requires ((piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1) /\ (h1 `contains` p.ptail) /\ (p.ptail @ h0).blink == (p.ptail @ h1).blink)) (ensures (piece_valid h1 p) /\ (p.phead @ h0).blink == (p.phead @ h1).blink)
let piece_remains_valid_f (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1) /\ (h1 `contains` p.ptail) /\ (p.ptail@h0).blink == (p.ptail@h1).blink)) (ensures (piece_valid h1 p) /\ (p.phead@h0).blink == (p.phead@h1).blink) = let nodes = reveal p.pnodes in if length nodes > 1 then ( fst_unsnoc_nodelist_valid h0 nodes; // assert (nodelist_valid h0 (fst (unsnoc nodes))); lemma_unsnoc_is_last nodes; // assert (Mod.loc_disjoint (Mod.loc_buffer p.ptail) (nodelist_fp0 (fst (unsnoc nodes)))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.ptail) (fst (unsnoc nodes)); // assert (nodelist_contained h1 (fst (unsnoc nodes))); // assert (h1 `contains` (snd (unsnoc nodes))); nodelist_append_contained h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_contained h1 (reveal p.pnodes)); // assert (piece_contained h1 p); extract_nodelist_conn h0 nodes (length nodes - 2); // let nl1 = fst (unsnoc nodes) in lemma_unsnoc_is_last (fst (unsnoc nodes)); // assert (last nl1 == nl1.[length nl1 - 1]); // assert (last nl1 == nl1.[length nodes - 2]); lemma_unsnoc_index nodes (length nodes - 2); // assert (last nl1 == nodes.[length nodes - 2]); // assert ((last (fst (unsnoc nodes)))@h0 |>> (hd [snd (unsnoc nodes)])); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); // assert (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1); extract_nodelist_contained h0 nodes (length nodes - 2); // assert (h0 `contains` last (fst (unsnoc nodes))); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); assert (Mod.loc_includes (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer (last (fst (unsnoc nodes))))); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); lemma_snoc_length (unsnoc nodes); // assert ((last (fst (unsnoc nodes)))@h0 == (last (fst (unsnoc nodes)))@h1); // assert ((last (fst (unsnoc nodes)))@h1 |>> (hd [snd (unsnoc nodes)])); // assert ((last (fst (unsnoc nodes))) <<| (hd [snd (unsnoc nodes)])@h1); nodelist_append_conn h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_conn h1 (reveal p.pnodes)); // assert (piece_conn h1 p); // assert ((p.phead@h0).blink == (p.phead@h1).blink); () ) else ()
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 1358, "start_col": 0, "start_line": 1313 }
(* Copyright 2008-2019 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 DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl let dll_valid (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d let piece_valid (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = piece_ghostly_connections p /\ piece_contained h0 p /\ piece_aa p /\ piece_conn h0 p let fragment_valid (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_ghostly_connections f /\ fragment_contained h0 f /\ fragment_aa f /\ fragment_conn h0 f /// Talk about payloads of nodes remaining constant let unchanged_node_val h0 h1 n = (h0 `contains` n ==> ((n@h0).p == (n@h1).p /\ h1 `contains` n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:nodelist 'a) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Useful operations on nodes let ( =|> ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ b@h0 == b@h1 /\ (a@h1) |>> b)) = a *= { !*a with flink = b } let ( <|= ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer b) h0 h1 /\ a@h0 == a@h1 /\ unchanged_node_val h0 h1 b /\ (b@h0).flink == (b@h1).flink /\ a <<| (b@h1))) = b *= { !*b with blink = a } let ( !=|> ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ (a@h1).flink == null)) = a *= { !*a with flink = null } let ( !<|= ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).flink == (a@h1).flink /\ (a@h1).blink == null)) = a *= { !*a with blink = null } /// Extraction lemmas: these allow one to use one of the properties /// above, which are defined inductively, to get the property at one /// of the latter elements of the list. let rec extract_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_contained h0 nl)) (ensures (h0 `contains` nl.[i])) = match i with | 0 -> () | _ -> extract_nodelist_contained h0 (tl nl) (i - 1) let rec extract_nodelist_fp0 (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer nl.[i]))) = match i with | 0 -> () | _ -> extract_nodelist_fp0 (tl nl) (i - 1) let rec extract_nodelist_aa_r (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_r nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 right))) = match i with | 0 -> () | _ -> extract_nodelist_aa_r (tl nl) (i - 1) let rec extract_nodelist_aa_l (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_l nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 left))) (decreases (length nl)) = if i = length nl - 1 then () else ( let a, b = unsnoc nl in lemma_unsnoc_length nl; let left, n, right = split3 nl i in lemma_unsnoc_split3 nl i; // assert (append (left) (n :: (fst (unsnoc right))) == a); extract_nodelist_aa_l a i; lemma_split3_unsnoc nl i ) let rec extract_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl - 1}) : Lemma (requires (nodelist_conn h0 nl)) (ensures ( (nl.[i]@h0 |>> nl.[i+1]) /\ (nl.[i] <<| nl.[i+1]@h0))) (decreases (length nl)) = match i with | 0 -> () | _ -> extract_nodelist_conn h0 (tl nl) (i - 1) /// Validity is maintained upon breaking the lists, via (hd :: tl) let rec nodelist_remains_aa_l (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa_l nl /\ length nl > 0)) (ensures (nodelist_aa_l (tl nl))) (decreases (length nl)) [SMTPat (nodelist_aa_l (tl nl))] = match nl with | [n] -> () | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; let ns', n' = unsnoc (tl nl) in // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (n' == n); // assert (ns' == tl ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns')); nodelist_remains_aa_l ns (* Rest of the validity predicates are held trivially due to their direction of definition *) /// Properties maintained upon breaking the list, via unsnoc let rec fst_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> fst_unsnoc_nodelist_fp0 ns let rec snd_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> snd_unsnoc_nodelist_fp0 ns let rec fst_unsnoc_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_contained h0 nl /\ length nl > 0)) (ensures (nodelist_contained h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_contained h0 (tl nl) let rec fst_unsnoc_nodelist_aa (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa nl /\ length nl > 0)) (ensures (nodelist_aa (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_aa (tl nl); // assert (nodelist_aa_l (fst (unsnoc nl))); let n :: ns = fst (unsnoc nl) in Mod.loc_disjoint_includes (Mod.loc_buffer n) (nodelist_fp0 (tl nl)) (Mod.loc_buffer n) (nodelist_fp0 ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (nodelist_aa_r (fst (unsnoc nl))); () let rec fst_unsnoc_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_conn h0 nl /\ length nl > 0)) (ensures (nodelist_conn h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_conn h0 (tl nl) let fst_unsnoc_nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_valid h0 nl /\ length nl > 0)) (ensures (nodelist_valid h0 (fst (unsnoc nl)))) = fst_unsnoc_nodelist_contained h0 nl; fst_unsnoc_nodelist_aa nl; fst_unsnoc_nodelist_conn h0 nl /// Footprints are included, even upon breaking nodelist even further let rec nodelist_includes_r_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let _, a = splitAt i nl in let _, b = splitAt j nl in Mod.loc_includes (nodelist_fp0 a) (nodelist_fp0 b))) (decreases (j - i)) = if i = j then () else ( let temp, a = splitAt i nl in lemma_splitAt nl temp a i; let temp, b = splitAt j nl in lemma_splitAt nl temp b j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (tl a == b); () ) else ( nodelist_includes_r_fp0 nl i (j - 1); nodelist_includes_r_fp0 nl (j - 1) j; let temp, c = splitAt (j - 1) nl in lemma_splitAt nl temp c (j - 1); Mod.loc_includes_trans (nodelist_fp0 a) (nodelist_fp0 c) (nodelist_fp0 b) ) ) let rec nodelist_includes_l_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let a, _ = splitAt i nl in let b, _ = splitAt j nl in Mod.loc_includes (nodelist_fp0 b) (nodelist_fp0 a))) (decreases (j - i)) = if i = j then () else ( let a, a' = splitAt i nl in lemma_splitAt nl a a' i; let b, b' = splitAt j nl in lemma_splitAt nl b b' j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (b == append a [hd a']); lemma_unsnoc_append a [hd a']; // assert (snd (unsnoc b) == hd a'); // assert (fst (unsnoc b) == a); fst_unsnoc_nodelist_fp0 b ) else ( nodelist_includes_l_fp0 nl i (j - 1); nodelist_includes_l_fp0 nl (j - 1) j; let c, c' = splitAt (j - 1) nl in lemma_splitAt nl c c' (j - 1); Mod.loc_includes_trans (nodelist_fp0 b) (nodelist_fp0 c) (nodelist_fp0 a) ) ) /// Total conversions between fragments, pieces, and dlls let tot_dll_to_piece (#t:Type) (h0:heap) (d:nonempty_dll t{dll_valid h0 d}) : Tot (p:piece t{piece_valid h0 p}) = { phead = d.lhead ; ptail = d.ltail ; pnodes = d.nodes } let tot_dll_to_fragment (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d /\ d.lhead =!= null}) : Tot (f:fragment t{fragment_valid h0 f}) = Frag1 (tot_dll_to_piece h0 d) let tot_piece_to_dll (#t:Type) (h0:heap) (p:piece t{ piece_valid h0 p /\ (p.phead@h0).blink == null /\ (p.ptail@h0).flink == null}) : Tot (d:dll t{dll_valid h0 d}) = { lhead = p.phead ; ltail = p.ptail ; nodes = p.pnodes } (* The conversions piece<->fragment are trivial *) /// Properties maintained when appending nodelists let rec nodelist_append_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) (ensures (nodelist_contained h0 (append nl1 nl2))) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_append_contained h0 nl1' nl2 let rec nodelist_append_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ( loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)))) = match nl1 with | [] -> () | n :: nl1' -> nodelist_append_fp0 nl1' nl2; // assert (loc_equiv // (nodelist_fp0 (append nl1' nl2)) // (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))); // assert (loc_equiv // (nodelist_fp0 nl1) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1'))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1')) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); loc_equiv_trans (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); () #set-options "--z3rlimit 20" let rec nodelist_append_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l nl1 /\ nodelist_aa_l nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_l (append nl1 nl2))) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; nodelist_append_fp0 nl1 nl2'; // assert (nodelist_aa_l nl2'); assert (Mod.loc_includes (nodelist_fp0 nl2) (nodelist_fp0 nl2')); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); lemma_unsnoc_is_last nl2; assert (Mod.loc_includes (nodelist_fp0 nl2) (Mod.loc_buffer n)); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl1)); // assert (loc_equiv (nodelist_fp0 (append nl1 nl2')) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2'))); nodelist_append_aa_l nl1 nl2'; // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (append nl1 nl2'))); lemma_unsnoc_append nl1 nl2; // assert (append nl1 nl2' == fst (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (fst (unsnoc (append nl1 nl2))))); () #reset-options let rec nodelist_append_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r nl1 /\ nodelist_aa_r nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_r (append nl1 nl2))) = match nl1 with | [] -> () | _ -> nodelist_append_fp0 (tl nl1) nl2; nodelist_append_aa_r (tl nl1) nl2 let nodelist_append_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa (append nl1 nl2))) = nodelist_append_aa_l nl1 nl2; nodelist_append_aa_r nl1 nl2 let rec nodelist_append_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_conn h0 (append nl1 nl2))) = match nl1 with | [_] -> () | _ -> nodelist_append_conn h0 (tl nl1) nl2 let nodelist_append_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_valid h0 (append nl1 nl2))) = nodelist_append_contained h0 nl1 nl2; nodelist_append_aa nl1 nl2; nodelist_append_conn h0 nl1 nl2 /// Useful property for for piece merging let loc_includes_union_r_inv (a b c:Mod.loc) : Lemma (requires (Mod.loc_includes a (Mod.loc_union b c))) (ensures (Mod.loc_includes a b /\ Mod.loc_includes a c)) = Mod.loc_includes_union_l b c b; Mod.loc_includes_trans a (Mod.loc_union b c) b; Mod.loc_includes_union_l b c c; Mod.loc_includes_trans a (Mod.loc_union b c) c /// Piece merging #set-options "--z3rlimit 10" val piece_merge (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Pure (piece t) (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (fun p -> (piece_valid h0 p) /\ (reveal p.pnodes == p1.pnodes `append` p2.pnodes))) let piece_merge #t h0 p1 p2 = let p = { phead = p1.phead ; ptail = p2.ptail ; pnodes = p1.pnodes ^@^ p2.pnodes } in lemma_append_last p1.pnodes p2.pnodes; nodelist_append_valid h0 p1.pnodes p2.pnodes; p #reset-options let piece_merge_fp0 (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Lemma (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (loc_equiv (piece_fp0 (piece_merge h0 p1 p2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)))) = let p = piece_merge h0 p1 p2 in let n1, n2, n = reveal p1.pnodes, reveal p2.pnodes, reveal p.pnodes in nodelist_append_fp0 n1 n2; // assert (loc_equiv (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); // assert (hd n1 == p1.phead); // assert (Mod.loc_includes (nodelist_fp0 n1) (Mod.loc_buffer p1.phead)); // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.phead)); // assert (last n2 == p2.ptail); extract_nodelist_fp0 n2 (length n2 - 1); lemma_unsnoc_is_last n2; // assert (Mod.loc_includes (nodelist_fp0 n2) (Mod.loc_buffer p2.ptail)); extract_nodelist_fp0 n (length n - 1); lemma_unsnoc_is_last n; // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.ptail)); loc_includes_union_r_inv (nodelist_fp0 n) (nodelist_fp0 n1) (nodelist_fp0 n2); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n1)); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n2)); // // assert (loc_equiv (nodelist_fp0 n) (piece_fp0 p)); extract_nodelist_fp0 n1 (length n1 - 1); lemma_unsnoc_is_last n1; // assert (loc_equiv (nodelist_fp0 n1) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 n2) (piece_fp0 p2)); // // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); Mod.loc_includes_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); Mod.loc_includes_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (Mod.loc_includes (piece_fp0 p) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // // assert (Mod.loc_includes (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (nodelist_fp0 n)); loc_equiv_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); loc_equiv_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); loc_equiv_trans (piece_fp0 p) (nodelist_fp0 n) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)) /// Fragment merging to a dll let rec fragment_defragmentable (#t:Type) (h0:heap) (f:fragment t{fragment_valid h0 f}) : GTot Type0 = let aux (p1 p2:(p:piece t{piece_valid h0 p})) = let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\(a <<| b@h0) in match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> aux p1 p2 | Frag3 p1 p2 p3 -> aux p1 p2 /\ aux p2 p3 let single_piece_fragment_valid (#t:Type) (h0:heap) (p:piece t) : Lemma (requires (piece_valid h0 p)) (ensures (fragment_valid h0 (Frag1 p))) = () #set-options "--z3rlimit 40 --initial_ifuel 2" let tot_defragmentable_fragment_to_dll (#t:Type) (h0:heap) (f:fragment t{ fragment_valid h0 f /\ fragment_defragmentable h0 f /\ (fragment_length f > 0 ==> (let a, b = match f with | Frag1 p1 -> p1, p1 | Frag2 p1 p2 -> p1, p2 | Frag3 p1 _ p3 -> p1, p3 in ((a.phead@h0).blink == null) /\ ((b.ptail@h0).flink == null))) }) : Tot (d:dll t{dll_valid h0 d /\ dll_fp0 d `loc_equiv` fragment_fp0 f /\ (reveal d.nodes == ( match f with | Frag0 -> [] | Frag1 p1 -> reveal p1.pnodes | Frag2 p1 p2 -> reveal p1.pnodes `append` reveal p2.pnodes | Frag3 p1 p2 p3 -> reveal p1.pnodes `append` reveal p2.pnodes `append` reveal p3.pnodes)) }) = match f with | Frag0 -> empty_list | Frag1 p1 -> tot_piece_to_dll h0 p1 | Frag2 p1 p2 -> piece_merge_fp0 h0 p1 p2; tot_piece_to_dll h0 (piece_merge h0 p1 p2) | Frag3 p1 p2 p3 -> piece_merge_fp0 h0 p1 p2; let p' = piece_merge h0 p1 p2 in piece_merge_fp0 h0 p' p3; tot_piece_to_dll h0 (piece_merge h0 p' p3) #reset-options /// Properties of nodelists maintained upon splitting nodelists let rec nodelist_split_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 (append nl1 nl2))) (ensures (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_split_contained h0 nl1' nl2 let rec nodelist_split_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = match nl1 with | [] | [_] -> () | _ -> match nl2 with | [] -> () | _ -> // assert (length nl1 > 1); // assert (length nl2 > 0); nodelist_split_fp0 (tl nl1) nl2; append_length nl1 nl2; nodelist_includes_r_fp0 (tl (append nl1 nl2)) 0 (length nl1 - 1); // assert (snd (splitAt 0 (tl (append nl1 nl2))) == tl (append nl1 nl2)); // assert (snd (splitAt (length nl1 - 1) (tl (append nl1 nl2))) == snd (splitAt (length nl1) (append nl1 nl2))); lemma_append_splitAt nl1 nl2; // assert (snd (splitAt (length nl1) (append nl1 nl2)) == nl2); // assert (Mod.loc_includes (nodelist_fp0 (tl (append nl1 nl2))) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl (append nl1 nl2)))); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (nodelist_fp0 (tl nl1)) (nodelist_fp0 nl2)); Mod.loc_disjoint_union_r (nodelist_fp0 nl2) (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1)); // assert (Mod.loc_disjoint (Mod.loc_union (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1))) (nodelist_fp0 nl2)); () #set-options "--z3rlimit 30" let rec nodelist_split_fp0_equiv (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ((loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2))))) = match nl1 with | [] -> () | n :: ns -> nodelist_split_fp0_equiv ns nl2; assert (loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2)))); // OBSERVE assert (loc_equiv (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns)) (nodelist_fp0 nl2))) // OBSERVE let rec nodelist_split_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l (append nl1 nl2))) (ensures (nodelist_aa_l nl1 /\ nodelist_aa_l nl2)) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; lemma_unsnoc_append nl1 nl2; // assert (nodelist_aa_l (append nl1 nl2)); // assert (nodelist_aa_l (append nl1 nl2')); nodelist_split_aa_l nl1 nl2'; // assert (nodelist_aa_l nl2'); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc nl2)); nodelist_append_fp0 nl1 nl2'; // assert (Mod.loc_includes (nodelist_fp0 (append nl1 nl2')) (nodelist_fp0 nl2')); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); // assert (nodelist_aa_l nl2); () #reset-options let rec nodelist_split_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (nodelist_aa_r nl1 /\ nodelist_aa_r nl2)) = match nl1 with | [] -> () | _ -> nodelist_split_aa_r (tl nl1) nl2; nodelist_append_fp0 (tl nl1) nl2 let nodelist_split_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa (append nl1 nl2))) (ensures (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = nodelist_split_fp0 nl1 nl2; nodelist_split_aa_l nl1 nl2; nodelist_split_aa_r nl1 nl2 let rec nodelist_split_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires ( (nodelist_conn h0 (append nl1 nl2)) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = match nl1 with | [_] -> () | _ -> nodelist_split_conn h0 (tl nl1) nl2 let nodelist_split_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 (append nl1 nl2) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = nodelist_split_contained h0 nl1 nl2; nodelist_split_aa nl1 nl2; nodelist_split_conn h0 nl1 nl2 /// Useful lemma to convert from dll_fp0 or piece_fp0 to nodelist_fp0 /// and vice-versa let dll_fp0_is_nodelist_fp0 (#t:Type) (d:dll t) : Lemma (requires (dll_ghostly_connections d)) (ensures (loc_equiv (dll_fp0 d) (nodelist_fp0 d.nodes))) = if length d.nodes > 0 then lemma_unsnoc_is_last d.nodes else () let piece_fp0_is_nodelist_fp0 (#t:Type) (p:piece t) : Lemma (requires (piece_ghostly_connections p)) (ensures (loc_equiv (piece_fp0 p) (nodelist_fp0 p.pnodes))) = lemma_unsnoc_is_last (reveal p.pnodes) /// Tot dll to fragment, with splitting #set-options "--z3rlimit 60 --initial_fuel 8 --initial_ifuel 1" let tot_dll_to_fragment_split (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d}) (n1 n2:pointer (node t)) : Pure (fragment t) (requires ( n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1@h0 |>> n2 /\ n1 <<| n2@h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == reveal p1.pnodes `append` reveal p2.pnodes))) = let split_nodes = elift2_p split_using d.nodes (hide n2) in lemma_split_using d.nodes n2; let l1 = elift1 fst split_nodes in let l2 = elift1 snd split_nodes in let p1 = { phead = d.lhead ; ptail = n1 ; pnodes = l1 } in let p2 = { phead = n2 ; ptail = d.ltail ; pnodes = l2 } in let f = Frag2 p1 p2 in dll_fp0_is_nodelist_fp0 d; // assert (loc_equiv (dll_fp0 d) (nodelist_fp0 (reveal d.nodes))); nodelist_split_fp0_equiv l1 l2; nodelist_split_valid h0 l1 l2; lemma_unsnoc_is_last l1; lemma_unsnoc_is_last l2; lemma_unsnoc_is_last (reveal d.nodes); // assert (piece_ghostly_connections p1); // assert ( n2 == hd (reveal l2) ); lemma_append_last l1 l2; // assert ( last (reveal l2) == last (append (reveal l1) (reveal l2)) ); // assert ( d.ltail == last (reveal l2) ); // assert (piece_ghostly_connections p2); // assert (fragment_ghostly_connections f); // assert (nodelist_contained h0 (reveal p1.pnodes)); // assert (nodelist_contained h0 (reveal p2.pnodes)); extract_nodelist_contained h0 l1 (length l1 - 1); // assert (h0 `contains` p1.ptail); // assert (fragment_contained h0 f); // assert (nodelist_aa (reveal p1.pnodes)); // assert (nodelist_aa (reveal p2.pnodes)); piece_fp0_is_nodelist_fp0 p1; piece_fp0_is_nodelist_fp0 p2; // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2)))); // assert (loc_equiv (nodelist_fp0 (reveal l1)) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 (reveal l2)) (piece_fp0 p2)); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2))) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); loc_equiv_trans (dll_fp0 d) (Mod.loc_union (nodelist_fp0 l1) (nodelist_fp0 l2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // assert (Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)); // assert (fragment_aa f); // assert (nodelist_conn h0 (reveal p1.pnodes)); // assert (nodelist_conn h0 (reveal p2.pnodes)); // assert (fragment_conn h0 f); f #reset-options /// Creating a dll from a single node. Pure and ST forms of this. let tot_node_to_dll (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (dll t) (requires ( (h0 `contains` n) /\ (((n@h0).flink == null)) /\ ((n@h0).blink == null))) (ensures (fun d -> dll_valid h0 d)) = { lhead = n ; ltail = n ; nodes = ~. n } let singleton_dll (#t:Type) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (h0 `contains` n))) (ensures (fun h0 d h1 -> Mod.modifies (Mod.loc_buffer n) h0 h1 /\ dll_valid h1 d /\ unchanged_node_vals h0 h1 d.nodes /\ reveal d.nodes == [n])) = !=|> n; !<|= n; tot_node_to_dll (ST.get ()) n /// Creating a piece from a single node. let tot_node_to_piece (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (piece t) (requires ( (h0 `contains` n))) (ensures (fun p -> piece_valid h0 p)) = { phead = n ; ptail = n ; pnodes = ~. n } /// Getting the "tail" of a piece let tot_piece_tail (#t:Type) (h0:heap) (p:piece t) (n:pointer (node t)) : Pure (piece t) (requires ( (piece_valid h0 p) /\ (n == (((p.phead)@h0).flink)) /\ (length p.pnodes > 1))) (ensures (fun q -> (piece_valid h0 q) /\ (reveal q.pnodes) == tl p.pnodes)) = { phead = n ; ptail = p.ptail ; pnodes = elift1_p (tot_to_gtot tl) p.pnodes } /// If a dll is valid, then both the forward and backward links of /// each of the nodes are contained in the heap, and disjoint from /// each other let lemma_dll_links_contained (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in (h0 `contains` (nodes.[i]@h0).flink) /\ (h0 `contains` (nodes.[i]@h0).blink))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else extract_nodelist_contained h0 nl (i - 1)); (if i = length nl - 1 then () else extract_nodelist_contained h0 nl (i + 1)); lemma_unsnoc_is_last nl #set-options "--z3rlimit 10 --initial_ifuel 2" let lemma_dll_links_disjoint (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in let left = (nodes.[i]@h0).blink in let right = (nodes.[i]@h0).flink in Mod.loc_disjoint (Mod.loc_buffer left) (Mod.loc_buffer right))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> lemma_unsnoc_length nl; let node_split = splitAt i nl in lemma_splitAt nl (fst node_split) (snd node_split) i; lemma_splitAt_index_hd i nl; let l1, x :: l2 = node_split in (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else ( if i = length nl - 1 then (lemma_unsnoc_is_last nl) else ( lemma_unsnoc_is_last l1; let left = last l1 in let right = hd l2 in lemma_splitAt_reindex_left i nl (length l1 - 1); // assert (left == (nl.[i]@h0).blink); lemma_splitAt_reindex_right i nl 1; // assert (right == (nl.[i]@h0).flink); nodelist_split_aa l1 (x :: l2); // assert (Mod.loc_disjoint (nodelist_fp0 l1) (nodelist_fp0 l2)); assert (Mod.loc_includes (nodelist_fp0 l1) (Mod.loc_buffer left)); // OBSERVE assert (Mod.loc_includes (nodelist_fp0 l2) (Mod.loc_buffer right)); // OBSERVE () ))) #reset-options /// When something unrelated to a XYZ is changed, the XYZ itself shall /// remain valid let rec nodelist_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (nl:nodelist t) : Lemma (requires ( (nodelist_valid h0 nl) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (nodelist_fp0 nl)))) (ensures (nodelist_valid h1 nl)) = match nl with | [] -> () | _ -> nodelist_remains_valid h0 h1 loc (tl nl) let piece_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (piece_fp0 p)))) (ensures (piece_valid h1 p)) = nodelist_remains_valid h0 h1 loc p.pnodes /// When outward facing pointers of ends of pieces are modified, they /// still remain valid #set-options "--z3rlimit 20" let piece_remains_valid_b (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.phead) h0 h1) /\ (h1 `contains` p.phead) /\ (p.phead@h0).flink == (p.phead@h1).flink)) (ensures (piece_valid h1 p) /\ (p.ptail@h0).flink == (p.ptail@h1).flink) = let nodes = p.pnodes in if length nodes > 1 then ( nodelist_includes_r_fp0 nodes 1 (length nodes - 1); lemma_unsnoc_is_last nodes; // assert (p.ptail == nodes.[length nodes - 1]); // assert (p.ptail@h0 == p.ptail@h1); // assert (h1 `contains` p.ptail); // assert (Mod.loc_disjoint (Mod.loc_buffer p.phead) (nodelist_fp0 (tl nodes))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.phead) (tl nodes) ) else ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "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": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> h1: DoublyLinkedList.heap -> p: DoublyLinkedList.piece t -> FStar.Pervasives.Lemma (requires DoublyLinkedList.piece_valid h0 p /\ LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer (Mkpiece?.ptail p)) h0 h1 /\ DoublyLinkedList.contains h1 (Mkpiece?.ptail p) /\ Mknode?.blink (Mkpiece?.ptail p @ h0) == Mknode?.blink (Mkpiece?.ptail p @ h1)) (ensures DoublyLinkedList.piece_valid h1 p /\ Mknode?.blink (Mkpiece?.phead p @ h0) == Mknode?.blink (Mkpiece?.phead p @ h1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.piece", "Prims.op_GreaterThan", "FStar.List.Tot.Base.length", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "Prims.unit", "DoublyLinkedList.nodelist_append_conn", "FStar.Pervasives.Native.fst", "Prims.list", "FStar.List.Tot.Base.unsnoc", "Prims.Cons", "FStar.Pervasives.Native.snd", "Prims.Nil", "FStar.List.Tot.Properties.lemma_snoc_length", "Prims._assert", "LowStar.Monotonic.Buffer.loc_includes", "DoublyLinkedList.nodelist_fp0", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "FStar.List.Tot.Base.last", "DoublyLinkedList.extract_nodelist_contained", "Prims.op_Subtraction", "FStar.List.Tot.Properties.lemma_unsnoc_index", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedList.extract_nodelist_conn", "DoublyLinkedList.nodelist_append_contained", "DoublyLinkedList.nodelist_remains_valid", "DoublyLinkedList.__proj__Mkpiece__item__ptail", "DoublyLinkedList.fst_unsnoc_nodelist_valid", "Prims.bool", "DoublyLinkedList.nodelist", "FStar.Ghost.reveal", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "Prims.l_and", "DoublyLinkedList.piece_valid", "LowStar.Monotonic.Buffer.modifies", "DoublyLinkedList.contains", "Prims.eq2", "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.__proj__Mknode__item__blink", "DoublyLinkedList.op_At", "Prims.squash", "DoublyLinkedList.__proj__Mkpiece__item__phead", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let piece_remains_valid_f (#t: Type) (h0 h1: heap) (p: piece t) : Lemma (requires ((piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1) /\ (h1 `contains` p.ptail) /\ (p.ptail @ h0).blink == (p.ptail @ h1).blink)) (ensures (piece_valid h1 p) /\ (p.phead @ h0).blink == (p.phead @ h1).blink) =
let nodes = reveal p.pnodes in if length nodes > 1 then (fst_unsnoc_nodelist_valid h0 nodes; lemma_unsnoc_is_last nodes; nodelist_remains_valid h0 h1 (Mod.loc_buffer p.ptail) (fst (unsnoc nodes)); nodelist_append_contained h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; extract_nodelist_conn h0 nodes (length nodes - 2); lemma_unsnoc_is_last (fst (unsnoc nodes)); lemma_unsnoc_index nodes (length nodes - 2); extract_nodelist_contained h0 nodes (length nodes - 2); assert (Mod.loc_includes (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer (last (fst (unsnoc nodes))))); lemma_snoc_length (unsnoc nodes); nodelist_append_conn h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; ())
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.blocks0
val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r})
val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r})
let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 14, "start_col": 0, "start_line": 14 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
x: Lib.IntTypes.size_nat -> m: Lib.IntTypes.size_pos -> r: Lib.IntTypes.size_pos{x <= m * r}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_nat", "Lib.IntTypes.size_pos", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "Prims.op_Division", "Prims.op_Subtraction", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star" ]
[]
false
false
false
false
false
let blocks0 x m =
if x = 0 then 1 else (x - 1) / m + 1
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp
val mk_bn_mod_exp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_st t len
val mk_bn_mod_exp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_st t len
let mk_bn_mod_exp #t len bn_mod_exp_precomp nBits n a bBits b = let r2, mu = BM.bn_mont_precomp nBits n in bn_mod_exp_precomp n mu r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 146, "start_col": 0, "start_line": 144 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len let mk_bn_mod_exp_precompr2 #t len bn_exp_precomp n r2 a bBits b = let mu = BI.mod_inv_limb n.[0] in BI.bn_mod_inv_limb_lemma n; bn_exp_precomp n mu r2 a bBits b let bn_mod_exp_vartime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_vartime_precomp len) n r2 a bBits b let bn_mod_exp_consttime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_consttime_precomp len) n r2 a bBits b val mk_bn_mod_exp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_st t len
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> bn_mod_exp_precomp: Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Montgomery.bn_mont_precomp" ]
[]
false
false
false
false
false
let mk_bn_mod_exp #t len bn_mod_exp_precomp nBits n a bBits b =
let r2, mu = BM.bn_mont_precomp nBits n in bn_mod_exp_precomp n mu r2 a bBits b
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_fw_precomp
val bn_mod_exp_fw_precomp: #t:limb_t -> len:BN.bn_len t -> l:size_pos{l < bits t /\ pow2 l * len <= max_size_t} -> bn_mod_exp_precomp_st t len
val bn_mod_exp_fw_precomp: #t:limb_t -> len:BN.bn_len t -> l:size_pos{l < bits t /\ pow2 l * len <= max_size_t} -> bn_mod_exp_precomp_st t len
let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 83, "end_line": 103, "start_col": 0, "start_line": 101 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> l: Lib.IntTypes.size_pos {l < Lib.IntTypes.bits t /\ Prims.pow2 l * len <= Lib.IntTypes.max_size_t} -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Lib.IntTypes.size_pos", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Prims.pow2", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont", "Hacl.Spec.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_fw" ]
[]
false
false
false
false
false
let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b =
mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_v
val bn_v : s: Hacl.Spec.Bignum.Definitions.lbignum t len -> Prims.nat
let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 75, "end_line": 28, "start_col": 0, "start_line": 28 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
s: Hacl.Spec.Bignum.Definitions.lbignum t len -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.nat" ]
[]
false
false
false
false
false
let bn_v (#t: limb_t) (#len: size_nat) (s: lbignum t len) =
eval_ #t len s len
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.eval_
val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat
val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat
let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1))
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 26, "start_col": 0, "start_line": 24 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Lib.IntTypes.size_nat -> s: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Prims.nat{i <= len} -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.pow2", "Lib.IntTypes.bits" ]
[ "recursion" ]
false
false
false
false
false
let rec eval_ #t len s i =
if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[ i - 1 ] * pow2 (bits t * (i - 1))
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_consttime_precompr2
val bn_mod_exp_consttime_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precompr2_st t len
val bn_mod_exp_consttime_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precompr2_st t len
let bn_mod_exp_consttime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_consttime_precomp len) n r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 135, "start_col": 0, "start_line": 134 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len let mk_bn_mod_exp_precompr2 #t len bn_exp_precomp n r2 a bBits b = let mu = BI.mod_inv_limb n.[0] in BI.bn_mod_inv_limb_lemma n; bn_exp_precomp n mu r2 a bBits b let bn_mod_exp_vartime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_vartime_precomp len) n r2 a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precompr2_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precompr2", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_consttime_precomp" ]
[]
false
false
false
false
false
let bn_mod_exp_consttime_precompr2 #t len n r2 a bBits b =
mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_consttime_precomp len) n r2 a bBits b
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_consttime
val bn_mod_exp_consttime: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_st t len
val bn_mod_exp_consttime: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_st t len
let bn_mod_exp_consttime #t len nBits n a bBits b = mk_bn_mod_exp len (bn_mod_exp_consttime_precomp len) nBits n a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 153, "start_col": 0, "start_line": 152 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len let mk_bn_mod_exp_precompr2 #t len bn_exp_precomp n r2 a bBits b = let mu = BI.mod_inv_limb n.[0] in BI.bn_mod_inv_limb_lemma n; bn_exp_precomp n mu r2 a bBits b let bn_mod_exp_vartime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_vartime_precomp len) n r2 a bBits b let bn_mod_exp_consttime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_consttime_precomp len) n r2 a bBits b val mk_bn_mod_exp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_st t len let mk_bn_mod_exp #t len bn_mod_exp_precomp nBits n a bBits b = let r2, mu = BM.bn_mont_precomp nBits n in bn_mod_exp_precomp n mu r2 a bBits b let bn_mod_exp_vartime #t len nBits n a bBits b = mk_bn_mod_exp len (bn_mod_exp_vartime_precomp len) nBits n a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_consttime_precomp" ]
[]
false
false
false
false
false
let bn_mod_exp_consttime #t len nBits n a bBits b =
mk_bn_mod_exp len (bn_mod_exp_consttime_precomp len) nBits n a bBits b
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_vartime_precomp
val bn_mod_exp_vartime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
val bn_mod_exp_vartime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 110, "start_col": 0, "start_line": 106 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.op_LessThan", "Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_vartime_threshold", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_rl_precomp", "Prims.bool", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_fw_precomp" ]
[]
false
false
false
false
false
let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b =
if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b
false
EverCrypt.Ed25519.fst
EverCrypt.Ed25519.verify
val verify: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature) (ensures fun h0 b h1 -> modifies0 h0 h1 /\ b == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
val verify: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature) (ensures fun h0 b h1 -> modifies0 h0 h1 /\ b == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify public_key msg_len msg signature = Hacl.Ed25519.verify public_key msg_len msg signature
{ "file_name": "providers/evercrypt/fst/EverCrypt.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 18, "start_col": 0, "start_line": 17 }
module EverCrypt.Ed25519 /// For now, only one implementation... to be improved in the future. let secret_to_public public_key private_key = Hacl.Ed25519.secret_to_public public_key private_key let expand_keys expanded_keys private_key = Hacl.Ed25519.expand_keys expanded_keys private_key let sign_expanded signature expanded_keys msg_len msg = Hacl.Ed25519.sign_expanded signature expanded_keys msg_len msg let sign signature private_key msg_len msg = Hacl.Ed25519.sign signature private_key msg_len msg
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Ed25519.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "EverCrypt.Ed25519.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> FStar.HyperStack.ST.Stack Prims.bool
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Hacl.Ed25519.verify", "Prims.bool" ]
[]
false
true
false
false
false
let verify public_key msg_len msg signature =
Hacl.Ed25519.verify public_key msg_len msg signature
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precompr2
val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len
val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len
let mk_bn_mod_exp_precompr2 #t len bn_exp_precomp n r2 a bBits b = let mu = BI.mod_inv_limb n.[0] in BI.bn_mod_inv_limb_lemma n; bn_exp_precomp n mu r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 128, "start_col": 0, "start_line": 125 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> bn_exp_precomp: Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precompr2_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.unit", "Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb", "Lib.Sequence.op_String_Access" ]
[]
false
false
false
false
false
let mk_bn_mod_exp_precompr2 #t len bn_exp_precomp n r2 a bBits b =
let mu = BI.mod_inv_limb n.[ 0 ] in BI.bn_mod_inv_limb_lemma n; bn_exp_precomp n mu r2 a bBits b
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.limb
val limb : t: Hacl.Spec.Bignum.Definitions.limb_t -> Type0
let limb (t:limb_t) = uint_t t SEC
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 20, "start_col": 0, "start_line": 20 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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.Spec.Bignum.Definitions.limb_t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC" ]
[]
false
false
false
true
true
let limb (t: limb_t) =
uint_t t SEC
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_vartime
val bn_mod_exp_vartime: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_st t len
val bn_mod_exp_vartime: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_st t len
let bn_mod_exp_vartime #t len nBits n a bBits b = mk_bn_mod_exp len (bn_mod_exp_vartime_precomp len) nBits n a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 70, "end_line": 150, "start_col": 0, "start_line": 149 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len let mk_bn_mod_exp_precompr2 #t len bn_exp_precomp n r2 a bBits b = let mu = BI.mod_inv_limb n.[0] in BI.bn_mod_inv_limb_lemma n; bn_exp_precomp n mu r2 a bBits b let bn_mod_exp_vartime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_vartime_precomp len) n r2 a bBits b let bn_mod_exp_consttime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_consttime_precomp len) n r2 a bBits b val mk_bn_mod_exp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_st t len let mk_bn_mod_exp #t len bn_mod_exp_precomp nBits n a bBits b = let r2, mu = BM.bn_mont_precomp nBits n in bn_mod_exp_precomp n mu r2 a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_vartime_precomp" ]
[]
false
false
false
false
false
let bn_mod_exp_vartime #t len nBits n a bBits b =
mk_bn_mod_exp len (bn_mod_exp_vartime_precomp len) nBits n a bBits b
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_rl_precomp
val bn_mod_exp_rl_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
val bn_mod_exp_rl_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 87, "end_line": 95, "start_col": 0, "start_line": 93 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont", "Hacl.Spec.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_bm_vartime" ]
[]
false
false
false
false
false
let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b =
mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b
false
EverCrypt.Ed25519.fst
EverCrypt.Ed25519.sign
val sign: signature:lbuffer uint8 64ul -> private_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> Stack unit (requires fun h -> live h signature /\ live h msg /\ live h private_key /\ disjoint signature msg /\ disjoint signature private_key) (ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\ as_seq h1 signature == Spec.Ed25519.sign (as_seq h0 private_key) (as_seq h0 msg))
val sign: signature:lbuffer uint8 64ul -> private_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> Stack unit (requires fun h -> live h signature /\ live h msg /\ live h private_key /\ disjoint signature msg /\ disjoint signature private_key) (ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\ as_seq h1 signature == Spec.Ed25519.sign (as_seq h0 private_key) (as_seq h0 msg))
let sign signature private_key msg_len msg = Hacl.Ed25519.sign signature private_key msg_len msg
{ "file_name": "providers/evercrypt/fst/EverCrypt.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 15, "start_col": 0, "start_line": 14 }
module EverCrypt.Ed25519 /// For now, only one implementation... to be improved in the future. let secret_to_public public_key private_key = Hacl.Ed25519.secret_to_public public_key private_key let expand_keys expanded_keys private_key = Hacl.Ed25519.expand_keys expanded_keys private_key let sign_expanded signature expanded_keys msg_len msg = Hacl.Ed25519.sign_expanded signature expanded_keys msg_len msg
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Ed25519.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "EverCrypt.Ed25519.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> private_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Hacl.Ed25519.sign", "Prims.unit" ]
[]
false
true
false
false
false
let sign signature private_key msg_len msg =
Hacl.Ed25519.sign signature private_key msg_len msg
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precomp_mont
val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len
val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len
let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 67, "start_col": 0, "start_line": 55 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> bn_exp_mont: Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_st t len -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_st", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.NatMod.pow_mod", "Hacl.Spec.Exponentiation.Lemmas.mod_exp_mont_ll_lemma", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Montgomery.bn_from_mont_lemma", "Hacl.Spec.Bignum.Montgomery.bn_from_mont", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Bignum.Montgomery.bn_to_mont_lemma", "Hacl.Spec.Bignum.Montgomery.bn_to_mont", "Hacl.Spec.Bignum.Definitions.bn_eval_bound" ]
[]
false
false
false
false
false
let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b =
bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_consttime_precomp
val bn_mod_exp_consttime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
val bn_mod_exp_consttime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 116, "start_col": 0, "start_line": 112 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.op_LessThan", "Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_consttime_threshold", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_mont_ladder_swap_precomp", "Prims.bool", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_fw_precomp" ]
[]
false
false
false
false
false
let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b =
if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b
false
EverCrypt.Ed25519.fst
EverCrypt.Ed25519.secret_to_public
val secret_to_public: public_key:lbuffer uint8 32ul -> private_key:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h public_key /\ live h private_key /\ disjoint public_key private_key) (ensures fun h0 _ h1 -> modifies (loc public_key) h0 h1 /\ as_seq h1 public_key == Spec.Ed25519.secret_to_public (as_seq h0 private_key))
val secret_to_public: public_key:lbuffer uint8 32ul -> private_key:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h public_key /\ live h private_key /\ disjoint public_key private_key) (ensures fun h0 _ h1 -> modifies (loc public_key) h0 h1 /\ as_seq h1 public_key == Spec.Ed25519.secret_to_public (as_seq h0 private_key))
let secret_to_public public_key private_key = Hacl.Ed25519.secret_to_public public_key private_key
{ "file_name": "providers/evercrypt/fst/EverCrypt.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 6, "start_col": 0, "start_line": 5 }
module EverCrypt.Ed25519 /// For now, only one implementation... to be improved in the future.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Ed25519.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "EverCrypt.Ed25519.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> private_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Hacl.Ed25519.secret_to_public", "Prims.unit" ]
[]
false
true
false
false
false
let secret_to_public public_key private_key =
Hacl.Ed25519.secret_to_public public_key private_key
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_vartime_precompr2
val bn_mod_exp_vartime_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precompr2_st t len
val bn_mod_exp_vartime_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precompr2_st t len
let bn_mod_exp_vartime_precompr2 #t len n r2 a bBits b = mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_vartime_precomp len) n r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 80, "end_line": 132, "start_col": 0, "start_line": 131 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b let bn_mod_exp_fw_precomp #t len l n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len (ME.bn_exp_mont_fw l) n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len (AE.bn_exp_almost_mont_fw l) n mu r2 a bBits b let bn_mod_exp_vartime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_vartime_threshold then bn_mod_exp_rl_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b let bn_mod_exp_consttime_precomp #t len n mu r2 a bBits b = if bBits < ME.bn_exp_mont_consttime_threshold then bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b else bn_mod_exp_fw_precomp #t len 4 n mu r2 a bBits b val mk_bn_mod_exp_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_exp_precomp:bn_mod_exp_precomp_st t len -> bn_mod_exp_precompr2_st t len let mk_bn_mod_exp_precompr2 #t len bn_exp_precomp n r2 a bBits b = let mu = BI.mod_inv_limb n.[0] in BI.bn_mod_inv_limb_lemma n; bn_exp_precomp n mu r2 a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precompr2_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precompr2", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_vartime_precomp" ]
[]
false
false
false
false
false
let bn_mod_exp_vartime_precompr2 #t len n r2 a bBits b =
mk_bn_mod_exp_precompr2 #t len (bn_mod_exp_vartime_precomp len) n r2 a bBits b
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_mont_ladder_swap_precomp
val bn_mod_exp_mont_ladder_swap_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
val bn_mod_exp_mont_ladder_swap_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_consttime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 99, "start_col": 0, "start_line": 97 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc let bn_mod_exp_rl_precomp #t len n mu r2 a bBits b = //mk_bn_mod_exp_precomp_mont #t len ME.bn_exp_mont_bm_vartime n mu r2 a bBits b mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_vartime n mu r2 a bBits b
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont", "Hacl.Spec.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_bm_consttime" ]
[]
false
false
false
false
false
let bn_mod_exp_mont_ladder_swap_precomp #t len n mu r2 a bBits b =
mk_bn_mod_exp_precomp_amont #t len AE.bn_exp_almost_mont_bm_consttime n mu r2 a bBits b
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont
val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len
val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len
let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 90, "start_col": 0, "start_line": 76 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r val mk_bn_mod_exp_precomp_mont: #t:limb_t -> len:BN.bn_len t -> bn_exp_mont:ME.bn_exp_mont_st t len -> bn_mod_exp_precomp_st t len let mk_bn_mod_exp_precomp_mont #t len bn_exp_mont n mu r2 a bBits b = bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; let accM = bn_exp_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; E.mod_exp_mont_ll_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc val mk_bn_mod_exp_precomp_amont: #t:limb_t -> len:BN.bn_len t -> bn_exp_almost_mont:AE.bn_exp_almost_mont_st t len -> bn_mod_exp_precomp_st t len
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Hacl.Spec.Bignum.bn_len t -> bn_exp_almost_mont: Hacl.Spec.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_st t len -> Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_st", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.NatMod.pow_mod", "Hacl.Spec.Exponentiation.Lemmas.mod_exp_mont_ll_mod_lemma", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Hacl.Spec.Bignum.Montgomery.bn_from_mont_lemma", "Hacl.Spec.Bignum.Montgomery.bn_from_mont", "Hacl.Spec.Montgomery.Lemmas.to_mont_lemma", "Hacl.Spec.Bignum.Montgomery.bn_to_mont_lemma", "Hacl.Spec.Bignum.Montgomery.bn_to_mont" ]
[]
false
false
false
false
false
let mk_bn_mod_exp_precomp_amont #t len bn_exp_almost_mont n mu r2 a bBits b =
bn_eval_bound n len; let aM = BM.bn_to_mont n mu r2 a in BM.bn_to_mont_lemma n mu r2 a; M.to_mont_lemma (bits t) len (bn_v n) (v mu) (bn_v a); let accM = bn_exp_almost_mont n mu aM bBits b in let acc = BM.bn_from_mont n mu accM in BM.bn_from_mont_lemma n mu accM; bn_eval_bound accM len; E.mod_exp_mont_ll_mod_lemma (bits t) len (bn_v n) (v mu) (bn_v a) (bn_v b) (bn_v accM); assert (bn_v acc == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)); acc
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_create1
val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c)
val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c)
let bn_eval_create1 #t c = bn_eval1 (create 1 c)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 58, "start_col": 0, "start_line": 57 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
c: Hacl.Spec.Bignum.Definitions.limb t -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.create 1 c) == Lib.IntTypes.v c)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Definitions.bn_eval1", "Lib.Sequence.create", "Prims.unit" ]
[]
true
false
true
false
false
let bn_eval_create1 #t c =
bn_eval1 (create 1 c)
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_snoc
val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len))
val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len))
let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 99, "start_col": 0, "start_line": 95 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> e: Hacl.Spec.Bignum.Definitions.limb t -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (FStar.Seq.Properties.snoc b e) == Hacl.Spec.Bignum.Definitions.bn_v b + Lib.IntTypes.v e * Prims.pow2 (Lib.IntTypes.bits t * len))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.Sequence.eq_intro", "Lib.Sequence.sub", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "FStar.Seq.Base.seq", "FStar.Seq.Properties.snoc" ]
[]
true
false
true
false
false
let bn_eval_snoc #t #len b e =
let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len + 1) #len b1 (slice #_ #(len + 1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b
false
DoublyLinkedList.fst
DoublyLinkedList.dll_insert_at_tail
val dll_insert_at_tail (#t: Type) (d: dll t) (n: pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) h0 h1 /\ ((dll_fp0 y) `loc_equiv` (B.loc_union (dll_fp0 d) (Mod.loc_buffer n))) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == snoc (reveal d.nodes, n)))
val dll_insert_at_tail (#t: Type) (d: dll t) (n: pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) h0 h1 /\ ((dll_fp0 y) `loc_equiv` (B.loc_union (dll_fp0 d) (Mod.loc_buffer n))) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == snoc (reveal d.nodes, n)))
let dll_insert_at_tail (#t:Type) (d:dll t) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) h0 h1 /\ (dll_fp0 y `loc_equiv` B.loc_union (dll_fp0 d) (Mod.loc_buffer n)) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == snoc (reveal d.nodes, n))) = if is_null d.lhead then ( singleton_dll n ) else ( let t = d.ltail in // let h0 = ST.get () in !=|> n; t <|= n; let h0' = ST.get () in lemma_dll_links_contained h0 d (length d.nodes - 1); lemma_unsnoc_is_last d.nodes; // assert (Mod.loc_disjoint (Mod.loc_buffer (t@h0).blink) (Mod.loc_buffer n)); t =|> n; let h1 = ST.get () in // let Frag1 p1 = tot_dll_to_fragment h0 d in let p = tot_node_to_piece h0 n in let f' = Frag2 p1 p in piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; piece_remains_valid_f h0' h1 p1; let y = tot_defragmentable_fragment_to_dll h1 f' in lemma_unsnoc_is_last y.nodes; lemma_snoc_unsnoc (reveal d.nodes, n); lemma_unsnoc_index y.nodes (length (y.nodes) - 2); lemma_unsnoc_length y.nodes; aux_unchanged_payload h0 h0' n y.nodes; aux_unchanged_payload h0' h1 t y.nodes; aux_unchanged_payload_transitive h0 h0' h1 y.nodes; y )
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 1541, "start_col": 0, "start_line": 1498 }
(* Copyright 2008-2019 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 DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl let dll_valid (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d let piece_valid (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = piece_ghostly_connections p /\ piece_contained h0 p /\ piece_aa p /\ piece_conn h0 p let fragment_valid (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_ghostly_connections f /\ fragment_contained h0 f /\ fragment_aa f /\ fragment_conn h0 f /// Talk about payloads of nodes remaining constant let unchanged_node_val h0 h1 n = (h0 `contains` n ==> ((n@h0).p == (n@h1).p /\ h1 `contains` n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:nodelist 'a) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Useful operations on nodes let ( =|> ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ b@h0 == b@h1 /\ (a@h1) |>> b)) = a *= { !*a with flink = b } let ( <|= ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer b) h0 h1 /\ a@h0 == a@h1 /\ unchanged_node_val h0 h1 b /\ (b@h0).flink == (b@h1).flink /\ a <<| (b@h1))) = b *= { !*b with blink = a } let ( !=|> ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ (a@h1).flink == null)) = a *= { !*a with flink = null } let ( !<|= ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).flink == (a@h1).flink /\ (a@h1).blink == null)) = a *= { !*a with blink = null } /// Extraction lemmas: these allow one to use one of the properties /// above, which are defined inductively, to get the property at one /// of the latter elements of the list. let rec extract_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_contained h0 nl)) (ensures (h0 `contains` nl.[i])) = match i with | 0 -> () | _ -> extract_nodelist_contained h0 (tl nl) (i - 1) let rec extract_nodelist_fp0 (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer nl.[i]))) = match i with | 0 -> () | _ -> extract_nodelist_fp0 (tl nl) (i - 1) let rec extract_nodelist_aa_r (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_r nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 right))) = match i with | 0 -> () | _ -> extract_nodelist_aa_r (tl nl) (i - 1) let rec extract_nodelist_aa_l (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_l nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 left))) (decreases (length nl)) = if i = length nl - 1 then () else ( let a, b = unsnoc nl in lemma_unsnoc_length nl; let left, n, right = split3 nl i in lemma_unsnoc_split3 nl i; // assert (append (left) (n :: (fst (unsnoc right))) == a); extract_nodelist_aa_l a i; lemma_split3_unsnoc nl i ) let rec extract_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl - 1}) : Lemma (requires (nodelist_conn h0 nl)) (ensures ( (nl.[i]@h0 |>> nl.[i+1]) /\ (nl.[i] <<| nl.[i+1]@h0))) (decreases (length nl)) = match i with | 0 -> () | _ -> extract_nodelist_conn h0 (tl nl) (i - 1) /// Validity is maintained upon breaking the lists, via (hd :: tl) let rec nodelist_remains_aa_l (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa_l nl /\ length nl > 0)) (ensures (nodelist_aa_l (tl nl))) (decreases (length nl)) [SMTPat (nodelist_aa_l (tl nl))] = match nl with | [n] -> () | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; let ns', n' = unsnoc (tl nl) in // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (n' == n); // assert (ns' == tl ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns')); nodelist_remains_aa_l ns (* Rest of the validity predicates are held trivially due to their direction of definition *) /// Properties maintained upon breaking the list, via unsnoc let rec fst_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> fst_unsnoc_nodelist_fp0 ns let rec snd_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> snd_unsnoc_nodelist_fp0 ns let rec fst_unsnoc_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_contained h0 nl /\ length nl > 0)) (ensures (nodelist_contained h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_contained h0 (tl nl) let rec fst_unsnoc_nodelist_aa (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa nl /\ length nl > 0)) (ensures (nodelist_aa (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_aa (tl nl); // assert (nodelist_aa_l (fst (unsnoc nl))); let n :: ns = fst (unsnoc nl) in Mod.loc_disjoint_includes (Mod.loc_buffer n) (nodelist_fp0 (tl nl)) (Mod.loc_buffer n) (nodelist_fp0 ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (nodelist_aa_r (fst (unsnoc nl))); () let rec fst_unsnoc_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_conn h0 nl /\ length nl > 0)) (ensures (nodelist_conn h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_conn h0 (tl nl) let fst_unsnoc_nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_valid h0 nl /\ length nl > 0)) (ensures (nodelist_valid h0 (fst (unsnoc nl)))) = fst_unsnoc_nodelist_contained h0 nl; fst_unsnoc_nodelist_aa nl; fst_unsnoc_nodelist_conn h0 nl /// Footprints are included, even upon breaking nodelist even further let rec nodelist_includes_r_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let _, a = splitAt i nl in let _, b = splitAt j nl in Mod.loc_includes (nodelist_fp0 a) (nodelist_fp0 b))) (decreases (j - i)) = if i = j then () else ( let temp, a = splitAt i nl in lemma_splitAt nl temp a i; let temp, b = splitAt j nl in lemma_splitAt nl temp b j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (tl a == b); () ) else ( nodelist_includes_r_fp0 nl i (j - 1); nodelist_includes_r_fp0 nl (j - 1) j; let temp, c = splitAt (j - 1) nl in lemma_splitAt nl temp c (j - 1); Mod.loc_includes_trans (nodelist_fp0 a) (nodelist_fp0 c) (nodelist_fp0 b) ) ) let rec nodelist_includes_l_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let a, _ = splitAt i nl in let b, _ = splitAt j nl in Mod.loc_includes (nodelist_fp0 b) (nodelist_fp0 a))) (decreases (j - i)) = if i = j then () else ( let a, a' = splitAt i nl in lemma_splitAt nl a a' i; let b, b' = splitAt j nl in lemma_splitAt nl b b' j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (b == append a [hd a']); lemma_unsnoc_append a [hd a']; // assert (snd (unsnoc b) == hd a'); // assert (fst (unsnoc b) == a); fst_unsnoc_nodelist_fp0 b ) else ( nodelist_includes_l_fp0 nl i (j - 1); nodelist_includes_l_fp0 nl (j - 1) j; let c, c' = splitAt (j - 1) nl in lemma_splitAt nl c c' (j - 1); Mod.loc_includes_trans (nodelist_fp0 b) (nodelist_fp0 c) (nodelist_fp0 a) ) ) /// Total conversions between fragments, pieces, and dlls let tot_dll_to_piece (#t:Type) (h0:heap) (d:nonempty_dll t{dll_valid h0 d}) : Tot (p:piece t{piece_valid h0 p}) = { phead = d.lhead ; ptail = d.ltail ; pnodes = d.nodes } let tot_dll_to_fragment (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d /\ d.lhead =!= null}) : Tot (f:fragment t{fragment_valid h0 f}) = Frag1 (tot_dll_to_piece h0 d) let tot_piece_to_dll (#t:Type) (h0:heap) (p:piece t{ piece_valid h0 p /\ (p.phead@h0).blink == null /\ (p.ptail@h0).flink == null}) : Tot (d:dll t{dll_valid h0 d}) = { lhead = p.phead ; ltail = p.ptail ; nodes = p.pnodes } (* The conversions piece<->fragment are trivial *) /// Properties maintained when appending nodelists let rec nodelist_append_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) (ensures (nodelist_contained h0 (append nl1 nl2))) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_append_contained h0 nl1' nl2 let rec nodelist_append_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ( loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)))) = match nl1 with | [] -> () | n :: nl1' -> nodelist_append_fp0 nl1' nl2; // assert (loc_equiv // (nodelist_fp0 (append nl1' nl2)) // (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))); // assert (loc_equiv // (nodelist_fp0 nl1) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1'))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1')) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); loc_equiv_trans (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); () #set-options "--z3rlimit 20" let rec nodelist_append_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l nl1 /\ nodelist_aa_l nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_l (append nl1 nl2))) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; nodelist_append_fp0 nl1 nl2'; // assert (nodelist_aa_l nl2'); assert (Mod.loc_includes (nodelist_fp0 nl2) (nodelist_fp0 nl2')); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); lemma_unsnoc_is_last nl2; assert (Mod.loc_includes (nodelist_fp0 nl2) (Mod.loc_buffer n)); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl1)); // assert (loc_equiv (nodelist_fp0 (append nl1 nl2')) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2'))); nodelist_append_aa_l nl1 nl2'; // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (append nl1 nl2'))); lemma_unsnoc_append nl1 nl2; // assert (append nl1 nl2' == fst (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (fst (unsnoc (append nl1 nl2))))); () #reset-options let rec nodelist_append_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r nl1 /\ nodelist_aa_r nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_r (append nl1 nl2))) = match nl1 with | [] -> () | _ -> nodelist_append_fp0 (tl nl1) nl2; nodelist_append_aa_r (tl nl1) nl2 let nodelist_append_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa (append nl1 nl2))) = nodelist_append_aa_l nl1 nl2; nodelist_append_aa_r nl1 nl2 let rec nodelist_append_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_conn h0 (append nl1 nl2))) = match nl1 with | [_] -> () | _ -> nodelist_append_conn h0 (tl nl1) nl2 let nodelist_append_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_valid h0 (append nl1 nl2))) = nodelist_append_contained h0 nl1 nl2; nodelist_append_aa nl1 nl2; nodelist_append_conn h0 nl1 nl2 /// Useful property for for piece merging let loc_includes_union_r_inv (a b c:Mod.loc) : Lemma (requires (Mod.loc_includes a (Mod.loc_union b c))) (ensures (Mod.loc_includes a b /\ Mod.loc_includes a c)) = Mod.loc_includes_union_l b c b; Mod.loc_includes_trans a (Mod.loc_union b c) b; Mod.loc_includes_union_l b c c; Mod.loc_includes_trans a (Mod.loc_union b c) c /// Piece merging #set-options "--z3rlimit 10" val piece_merge (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Pure (piece t) (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (fun p -> (piece_valid h0 p) /\ (reveal p.pnodes == p1.pnodes `append` p2.pnodes))) let piece_merge #t h0 p1 p2 = let p = { phead = p1.phead ; ptail = p2.ptail ; pnodes = p1.pnodes ^@^ p2.pnodes } in lemma_append_last p1.pnodes p2.pnodes; nodelist_append_valid h0 p1.pnodes p2.pnodes; p #reset-options let piece_merge_fp0 (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Lemma (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (loc_equiv (piece_fp0 (piece_merge h0 p1 p2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)))) = let p = piece_merge h0 p1 p2 in let n1, n2, n = reveal p1.pnodes, reveal p2.pnodes, reveal p.pnodes in nodelist_append_fp0 n1 n2; // assert (loc_equiv (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); // assert (hd n1 == p1.phead); // assert (Mod.loc_includes (nodelist_fp0 n1) (Mod.loc_buffer p1.phead)); // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.phead)); // assert (last n2 == p2.ptail); extract_nodelist_fp0 n2 (length n2 - 1); lemma_unsnoc_is_last n2; // assert (Mod.loc_includes (nodelist_fp0 n2) (Mod.loc_buffer p2.ptail)); extract_nodelist_fp0 n (length n - 1); lemma_unsnoc_is_last n; // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.ptail)); loc_includes_union_r_inv (nodelist_fp0 n) (nodelist_fp0 n1) (nodelist_fp0 n2); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n1)); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n2)); // // assert (loc_equiv (nodelist_fp0 n) (piece_fp0 p)); extract_nodelist_fp0 n1 (length n1 - 1); lemma_unsnoc_is_last n1; // assert (loc_equiv (nodelist_fp0 n1) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 n2) (piece_fp0 p2)); // // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); Mod.loc_includes_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); Mod.loc_includes_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (Mod.loc_includes (piece_fp0 p) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // // assert (Mod.loc_includes (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (nodelist_fp0 n)); loc_equiv_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); loc_equiv_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); loc_equiv_trans (piece_fp0 p) (nodelist_fp0 n) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)) /// Fragment merging to a dll let rec fragment_defragmentable (#t:Type) (h0:heap) (f:fragment t{fragment_valid h0 f}) : GTot Type0 = let aux (p1 p2:(p:piece t{piece_valid h0 p})) = let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\(a <<| b@h0) in match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> aux p1 p2 | Frag3 p1 p2 p3 -> aux p1 p2 /\ aux p2 p3 let single_piece_fragment_valid (#t:Type) (h0:heap) (p:piece t) : Lemma (requires (piece_valid h0 p)) (ensures (fragment_valid h0 (Frag1 p))) = () #set-options "--z3rlimit 40 --initial_ifuel 2" let tot_defragmentable_fragment_to_dll (#t:Type) (h0:heap) (f:fragment t{ fragment_valid h0 f /\ fragment_defragmentable h0 f /\ (fragment_length f > 0 ==> (let a, b = match f with | Frag1 p1 -> p1, p1 | Frag2 p1 p2 -> p1, p2 | Frag3 p1 _ p3 -> p1, p3 in ((a.phead@h0).blink == null) /\ ((b.ptail@h0).flink == null))) }) : Tot (d:dll t{dll_valid h0 d /\ dll_fp0 d `loc_equiv` fragment_fp0 f /\ (reveal d.nodes == ( match f with | Frag0 -> [] | Frag1 p1 -> reveal p1.pnodes | Frag2 p1 p2 -> reveal p1.pnodes `append` reveal p2.pnodes | Frag3 p1 p2 p3 -> reveal p1.pnodes `append` reveal p2.pnodes `append` reveal p3.pnodes)) }) = match f with | Frag0 -> empty_list | Frag1 p1 -> tot_piece_to_dll h0 p1 | Frag2 p1 p2 -> piece_merge_fp0 h0 p1 p2; tot_piece_to_dll h0 (piece_merge h0 p1 p2) | Frag3 p1 p2 p3 -> piece_merge_fp0 h0 p1 p2; let p' = piece_merge h0 p1 p2 in piece_merge_fp0 h0 p' p3; tot_piece_to_dll h0 (piece_merge h0 p' p3) #reset-options /// Properties of nodelists maintained upon splitting nodelists let rec nodelist_split_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 (append nl1 nl2))) (ensures (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_split_contained h0 nl1' nl2 let rec nodelist_split_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = match nl1 with | [] | [_] -> () | _ -> match nl2 with | [] -> () | _ -> // assert (length nl1 > 1); // assert (length nl2 > 0); nodelist_split_fp0 (tl nl1) nl2; append_length nl1 nl2; nodelist_includes_r_fp0 (tl (append nl1 nl2)) 0 (length nl1 - 1); // assert (snd (splitAt 0 (tl (append nl1 nl2))) == tl (append nl1 nl2)); // assert (snd (splitAt (length nl1 - 1) (tl (append nl1 nl2))) == snd (splitAt (length nl1) (append nl1 nl2))); lemma_append_splitAt nl1 nl2; // assert (snd (splitAt (length nl1) (append nl1 nl2)) == nl2); // assert (Mod.loc_includes (nodelist_fp0 (tl (append nl1 nl2))) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl (append nl1 nl2)))); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (nodelist_fp0 (tl nl1)) (nodelist_fp0 nl2)); Mod.loc_disjoint_union_r (nodelist_fp0 nl2) (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1)); // assert (Mod.loc_disjoint (Mod.loc_union (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1))) (nodelist_fp0 nl2)); () #set-options "--z3rlimit 30" let rec nodelist_split_fp0_equiv (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ((loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2))))) = match nl1 with | [] -> () | n :: ns -> nodelist_split_fp0_equiv ns nl2; assert (loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2)))); // OBSERVE assert (loc_equiv (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns)) (nodelist_fp0 nl2))) // OBSERVE let rec nodelist_split_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l (append nl1 nl2))) (ensures (nodelist_aa_l nl1 /\ nodelist_aa_l nl2)) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; lemma_unsnoc_append nl1 nl2; // assert (nodelist_aa_l (append nl1 nl2)); // assert (nodelist_aa_l (append nl1 nl2')); nodelist_split_aa_l nl1 nl2'; // assert (nodelist_aa_l nl2'); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc nl2)); nodelist_append_fp0 nl1 nl2'; // assert (Mod.loc_includes (nodelist_fp0 (append nl1 nl2')) (nodelist_fp0 nl2')); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); // assert (nodelist_aa_l nl2); () #reset-options let rec nodelist_split_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (nodelist_aa_r nl1 /\ nodelist_aa_r nl2)) = match nl1 with | [] -> () | _ -> nodelist_split_aa_r (tl nl1) nl2; nodelist_append_fp0 (tl nl1) nl2 let nodelist_split_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa (append nl1 nl2))) (ensures (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = nodelist_split_fp0 nl1 nl2; nodelist_split_aa_l nl1 nl2; nodelist_split_aa_r nl1 nl2 let rec nodelist_split_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires ( (nodelist_conn h0 (append nl1 nl2)) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = match nl1 with | [_] -> () | _ -> nodelist_split_conn h0 (tl nl1) nl2 let nodelist_split_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 (append nl1 nl2) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = nodelist_split_contained h0 nl1 nl2; nodelist_split_aa nl1 nl2; nodelist_split_conn h0 nl1 nl2 /// Useful lemma to convert from dll_fp0 or piece_fp0 to nodelist_fp0 /// and vice-versa let dll_fp0_is_nodelist_fp0 (#t:Type) (d:dll t) : Lemma (requires (dll_ghostly_connections d)) (ensures (loc_equiv (dll_fp0 d) (nodelist_fp0 d.nodes))) = if length d.nodes > 0 then lemma_unsnoc_is_last d.nodes else () let piece_fp0_is_nodelist_fp0 (#t:Type) (p:piece t) : Lemma (requires (piece_ghostly_connections p)) (ensures (loc_equiv (piece_fp0 p) (nodelist_fp0 p.pnodes))) = lemma_unsnoc_is_last (reveal p.pnodes) /// Tot dll to fragment, with splitting #set-options "--z3rlimit 60 --initial_fuel 8 --initial_ifuel 1" let tot_dll_to_fragment_split (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d}) (n1 n2:pointer (node t)) : Pure (fragment t) (requires ( n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1@h0 |>> n2 /\ n1 <<| n2@h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == reveal p1.pnodes `append` reveal p2.pnodes))) = let split_nodes = elift2_p split_using d.nodes (hide n2) in lemma_split_using d.nodes n2; let l1 = elift1 fst split_nodes in let l2 = elift1 snd split_nodes in let p1 = { phead = d.lhead ; ptail = n1 ; pnodes = l1 } in let p2 = { phead = n2 ; ptail = d.ltail ; pnodes = l2 } in let f = Frag2 p1 p2 in dll_fp0_is_nodelist_fp0 d; // assert (loc_equiv (dll_fp0 d) (nodelist_fp0 (reveal d.nodes))); nodelist_split_fp0_equiv l1 l2; nodelist_split_valid h0 l1 l2; lemma_unsnoc_is_last l1; lemma_unsnoc_is_last l2; lemma_unsnoc_is_last (reveal d.nodes); // assert (piece_ghostly_connections p1); // assert ( n2 == hd (reveal l2) ); lemma_append_last l1 l2; // assert ( last (reveal l2) == last (append (reveal l1) (reveal l2)) ); // assert ( d.ltail == last (reveal l2) ); // assert (piece_ghostly_connections p2); // assert (fragment_ghostly_connections f); // assert (nodelist_contained h0 (reveal p1.pnodes)); // assert (nodelist_contained h0 (reveal p2.pnodes)); extract_nodelist_contained h0 l1 (length l1 - 1); // assert (h0 `contains` p1.ptail); // assert (fragment_contained h0 f); // assert (nodelist_aa (reveal p1.pnodes)); // assert (nodelist_aa (reveal p2.pnodes)); piece_fp0_is_nodelist_fp0 p1; piece_fp0_is_nodelist_fp0 p2; // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2)))); // assert (loc_equiv (nodelist_fp0 (reveal l1)) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 (reveal l2)) (piece_fp0 p2)); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2))) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); loc_equiv_trans (dll_fp0 d) (Mod.loc_union (nodelist_fp0 l1) (nodelist_fp0 l2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // assert (Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)); // assert (fragment_aa f); // assert (nodelist_conn h0 (reveal p1.pnodes)); // assert (nodelist_conn h0 (reveal p2.pnodes)); // assert (fragment_conn h0 f); f #reset-options /// Creating a dll from a single node. Pure and ST forms of this. let tot_node_to_dll (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (dll t) (requires ( (h0 `contains` n) /\ (((n@h0).flink == null)) /\ ((n@h0).blink == null))) (ensures (fun d -> dll_valid h0 d)) = { lhead = n ; ltail = n ; nodes = ~. n } let singleton_dll (#t:Type) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (h0 `contains` n))) (ensures (fun h0 d h1 -> Mod.modifies (Mod.loc_buffer n) h0 h1 /\ dll_valid h1 d /\ unchanged_node_vals h0 h1 d.nodes /\ reveal d.nodes == [n])) = !=|> n; !<|= n; tot_node_to_dll (ST.get ()) n /// Creating a piece from a single node. let tot_node_to_piece (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (piece t) (requires ( (h0 `contains` n))) (ensures (fun p -> piece_valid h0 p)) = { phead = n ; ptail = n ; pnodes = ~. n } /// Getting the "tail" of a piece let tot_piece_tail (#t:Type) (h0:heap) (p:piece t) (n:pointer (node t)) : Pure (piece t) (requires ( (piece_valid h0 p) /\ (n == (((p.phead)@h0).flink)) /\ (length p.pnodes > 1))) (ensures (fun q -> (piece_valid h0 q) /\ (reveal q.pnodes) == tl p.pnodes)) = { phead = n ; ptail = p.ptail ; pnodes = elift1_p (tot_to_gtot tl) p.pnodes } /// If a dll is valid, then both the forward and backward links of /// each of the nodes are contained in the heap, and disjoint from /// each other let lemma_dll_links_contained (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in (h0 `contains` (nodes.[i]@h0).flink) /\ (h0 `contains` (nodes.[i]@h0).blink))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else extract_nodelist_contained h0 nl (i - 1)); (if i = length nl - 1 then () else extract_nodelist_contained h0 nl (i + 1)); lemma_unsnoc_is_last nl #set-options "--z3rlimit 10 --initial_ifuel 2" let lemma_dll_links_disjoint (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in let left = (nodes.[i]@h0).blink in let right = (nodes.[i]@h0).flink in Mod.loc_disjoint (Mod.loc_buffer left) (Mod.loc_buffer right))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> lemma_unsnoc_length nl; let node_split = splitAt i nl in lemma_splitAt nl (fst node_split) (snd node_split) i; lemma_splitAt_index_hd i nl; let l1, x :: l2 = node_split in (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else ( if i = length nl - 1 then (lemma_unsnoc_is_last nl) else ( lemma_unsnoc_is_last l1; let left = last l1 in let right = hd l2 in lemma_splitAt_reindex_left i nl (length l1 - 1); // assert (left == (nl.[i]@h0).blink); lemma_splitAt_reindex_right i nl 1; // assert (right == (nl.[i]@h0).flink); nodelist_split_aa l1 (x :: l2); // assert (Mod.loc_disjoint (nodelist_fp0 l1) (nodelist_fp0 l2)); assert (Mod.loc_includes (nodelist_fp0 l1) (Mod.loc_buffer left)); // OBSERVE assert (Mod.loc_includes (nodelist_fp0 l2) (Mod.loc_buffer right)); // OBSERVE () ))) #reset-options /// When something unrelated to a XYZ is changed, the XYZ itself shall /// remain valid let rec nodelist_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (nl:nodelist t) : Lemma (requires ( (nodelist_valid h0 nl) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (nodelist_fp0 nl)))) (ensures (nodelist_valid h1 nl)) = match nl with | [] -> () | _ -> nodelist_remains_valid h0 h1 loc (tl nl) let piece_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (piece_fp0 p)))) (ensures (piece_valid h1 p)) = nodelist_remains_valid h0 h1 loc p.pnodes /// When outward facing pointers of ends of pieces are modified, they /// still remain valid #set-options "--z3rlimit 20" let piece_remains_valid_b (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.phead) h0 h1) /\ (h1 `contains` p.phead) /\ (p.phead@h0).flink == (p.phead@h1).flink)) (ensures (piece_valid h1 p) /\ (p.ptail@h0).flink == (p.ptail@h1).flink) = let nodes = p.pnodes in if length nodes > 1 then ( nodelist_includes_r_fp0 nodes 1 (length nodes - 1); lemma_unsnoc_is_last nodes; // assert (p.ptail == nodes.[length nodes - 1]); // assert (p.ptail@h0 == p.ptail@h1); // assert (h1 `contains` p.ptail); // assert (Mod.loc_disjoint (Mod.loc_buffer p.phead) (nodelist_fp0 (tl nodes))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.phead) (tl nodes) ) else () let piece_remains_valid_f (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1) /\ (h1 `contains` p.ptail) /\ (p.ptail@h0).blink == (p.ptail@h1).blink)) (ensures (piece_valid h1 p) /\ (p.phead@h0).blink == (p.phead@h1).blink) = let nodes = reveal p.pnodes in if length nodes > 1 then ( fst_unsnoc_nodelist_valid h0 nodes; // assert (nodelist_valid h0 (fst (unsnoc nodes))); lemma_unsnoc_is_last nodes; // assert (Mod.loc_disjoint (Mod.loc_buffer p.ptail) (nodelist_fp0 (fst (unsnoc nodes)))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.ptail) (fst (unsnoc nodes)); // assert (nodelist_contained h1 (fst (unsnoc nodes))); // assert (h1 `contains` (snd (unsnoc nodes))); nodelist_append_contained h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_contained h1 (reveal p.pnodes)); // assert (piece_contained h1 p); extract_nodelist_conn h0 nodes (length nodes - 2); // let nl1 = fst (unsnoc nodes) in lemma_unsnoc_is_last (fst (unsnoc nodes)); // assert (last nl1 == nl1.[length nl1 - 1]); // assert (last nl1 == nl1.[length nodes - 2]); lemma_unsnoc_index nodes (length nodes - 2); // assert (last nl1 == nodes.[length nodes - 2]); // assert ((last (fst (unsnoc nodes)))@h0 |>> (hd [snd (unsnoc nodes)])); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); // assert (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1); extract_nodelist_contained h0 nodes (length nodes - 2); // assert (h0 `contains` last (fst (unsnoc nodes))); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); assert (Mod.loc_includes (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer (last (fst (unsnoc nodes))))); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); lemma_snoc_length (unsnoc nodes); // assert ((last (fst (unsnoc nodes)))@h0 == (last (fst (unsnoc nodes)))@h1); // assert ((last (fst (unsnoc nodes)))@h1 |>> (hd [snd (unsnoc nodes)])); // assert ((last (fst (unsnoc nodes))) <<| (hd [snd (unsnoc nodes)])@h1); nodelist_append_conn h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_conn h1 (reveal p.pnodes)); // assert (piece_conn h1 p); // assert ((p.phead@h0).blink == (p.phead@h1).blink); () ) else () #reset-options /// Testing is a node is within a dll or not let node_not_in_dll (#t:Type) (h0:heap) (n:pointer (node t)) (d:dll t) = let m1 = Mod.loc_buffer n in let m2 = dll_fp0 d in Mod.loc_disjoint m1 m2 /// An empty dll has no nodes let _auto_empty_dll (#t:Type) (h0:heap) (d:dll t) : Lemma (requires (dll_valid h0 d /\ (d.lhead == null \/ d.ltail == null))) (ensures (reveal d.nodes == [])) [SMTPat (dll_valid h0 d); SMTPat (reveal d.nodes)] = () /// Be able to easily reason about unchanged payloads let rec aux_unchanged_payload #t h0 h1 n0 (nl:nodelist t) : Lemma (requires (Mod.modifies (Mod.loc_buffer n0) h0 h1 /\ (n0@h0).p == (n0@h1).p /\ (nodelist_aa_r nl) /\ (n0 `memP` nl \/ Mod.loc_disjoint (Mod.loc_buffer n0) (nodelist_fp0 nl)) )) (ensures (unchanged_node_vals h0 h1 nl)) (decreases (length nl)) = match nl with | [] -> () | n :: nl' -> aux_unchanged_payload h0 h1 n0 nl'; assert (n0 `memP` nl ==> (n == n0 \/ n0 `memP` nl')); let goal () = unchanged_node_val h0 h1 n in FStar.Classical.or_elim #_ #_ #goal (fun (_:unit{n0 `memP` nl}) -> FStar.Classical.or_elim #_ #_ #goal (fun (_:unit{n == n0}) -> ()) (fun (_:unit{n0 `memP` nl'}) -> let i = nl' `index_of` n0 in extract_nodelist_fp0 nl' i)) (fun (_:unit{Mod.loc_disjoint (Mod.loc_buffer n0) (nodelist_fp0 nl)}) -> ()) let rec aux_unchanged_payload_nomod #t h0 h1 (nl:nodelist t) : Lemma (requires (Mod.modifies Mod.loc_none h0 h1)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: nl' -> aux_unchanged_payload_nomod h0 h1 nl' let rec aux_unchanged_payload_transitive #t h0 h1 h2 (nl:nodelist t) : Lemma (requires (unchanged_node_vals h0 h1 nl /\ unchanged_node_vals h1 h2 nl)) (ensures (unchanged_node_vals h0 h2 nl)) = match nl with | [] -> () | _ :: nl' -> aux_unchanged_payload_transitive h0 h1 h2 nl' let rec aux_unchanged_payload_append #t h0 h1 (nl1 nl2:nodelist t) : Lemma (requires (unchanged_node_vals h0 h1 nl1 /\ unchanged_node_vals h0 h1 nl2)) (ensures (unchanged_node_vals h0 h1 (nl1 `append` nl2))) = match nl1 with | [] -> () | n :: nl' -> aux_unchanged_payload_append h0 h1 nl' nl2 /// Now for the actual ST operations that will be exposed :) #set-options "--z3rlimit 500 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head (#t:Type) (d:dll t) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.lhead)) h0 h1 /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == n :: reveal d.nodes)) = if is_null d.lhead then ( singleton_dll n ) else ( let h = d.lhead in // let h0 = ST.get () in !<|= n; n =|> h; let h0' = ST.get () in n <|= h; let h1 = ST.get () in // aux_unchanged_payload h0 h0' n d.nodes; aux_unchanged_payload h0' h1 h d.nodes; aux_unchanged_payload_transitive h0 h0' h1 d.nodes; // let Frag1 p1 = tot_dll_to_fragment h0 d in let p = tot_node_to_piece h0 n in let f' = Frag2 p p1 in // assert (fragment_valid h1 [p]); // assert (fragment_ghostly_connections f); // assert (length f = 1); // assert (h1 `contains` (hd f).phead); piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; // assert (piece_valid h0' (hd f)); piece_remains_valid_b h0' h1 p1; // assert (h1 `contains` (hd f).ptail); // assert (nodelist_contained h1 (reveal (hd f).pnodes)); // assert (piece_contained h1 (hd f)); // assert (fragment_contained h1 f); // assert (fragment_aa f); // assert (nodelist_conn h1 (reveal (f.[0]).pnodes)); // assert (fragment_conn h1 f); // assert (fragment_valid h1 f); // assert (fragment_valid h1 f'); // assert (fragment_defragmentable h1 f'); // assert (length f' > 0); // assert (is_null ((hd f').phead@h1).blink); // assert (is_null ((last f').ptail@h0).flink); // assert (is_null ((last f').ptail@h0').flink); // assert (is_null ((last f').ptail@h1).flink); let y = tot_defragmentable_fragment_to_dll h1 f' in // assert (dll_valid h1 y); y ) #reset-options #set-options "--z3rlimit 500 --max_fuel 2 --max_ifuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "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": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 2, "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": 500, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedList.dll t -> n: LowStar.Buffer.pointer (DoublyLinkedList.node t) -> FStar.HyperStack.ST.StackInline (DoublyLinkedList.dll t)
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedList.dll", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "DoublyLinkedList.singleton_dll", "Prims.bool", "DoublyLinkedList.piece", "Prims.unit", "DoublyLinkedList.aux_unchanged_payload_transitive", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "DoublyLinkedList.aux_unchanged_payload", "FStar.List.Tot.Properties.lemma_unsnoc_length", "FStar.List.Tot.Properties.lemma_unsnoc_index", "Prims.op_Subtraction", "FStar.List.Tot.Base.length", "FStar.List.Tot.Properties.lemma_snoc_unsnoc", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "Prims.l_and", "DoublyLinkedList.dll_valid", "DoublyLinkedList.loc_equiv", "DoublyLinkedList.dll_fp0", "DoublyLinkedList.fragment_fp0", "Prims.eq2", "Prims.Nil", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "FStar.List.Tot.Base.append", "DoublyLinkedList.tot_defragmentable_fragment_to_dll", "DoublyLinkedList.piece_remains_valid_f", "DoublyLinkedList.piece_remains_valid", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.fragment", "DoublyLinkedList.Frag2", "DoublyLinkedList.tot_node_to_piece", "DoublyLinkedList.fragment_valid", "DoublyLinkedList.tot_dll_to_fragment", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "DoublyLinkedList.op_Equals_Bar_Greater", "DoublyLinkedList.lemma_dll_links_contained", "DoublyLinkedList.op_Less_Bar_Equals", "DoublyLinkedList.op_Bang_Equals_Bar_Greater", "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.__proj__Mkdll__item__ltail", "LowStar.Monotonic.Buffer.is_null", "DoublyLinkedList.__proj__Mkdll__item__lhead", "DoublyLinkedList.contains", "DoublyLinkedList.node_not_in_dll", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "DoublyLinkedList.unchanged_node_vals", "FStar.List.Tot.Base.snoc" ]
[]
false
true
false
false
false
let dll_insert_at_tail (#t: Type) (d: dll t) (n: pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) h0 h1 /\ ((dll_fp0 y) `loc_equiv` (B.loc_union (dll_fp0 d) (Mod.loc_buffer n))) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == snoc (reveal d.nodes, n))) =
if is_null d.lhead then (singleton_dll n) else (let t = d.ltail in let h0 = ST.get () in !=|>n; t <|= n; let h0' = ST.get () in lemma_dll_links_contained h0 d (length d.nodes - 1); lemma_unsnoc_is_last d.nodes; t =|> n; let h1 = ST.get () in let Frag1 p1 = tot_dll_to_fragment h0 d in let p = tot_node_to_piece h0 n in let f' = Frag2 p1 p in piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; piece_remains_valid_f h0' h1 p1; let y = tot_defragmentable_fragment_to_dll h1 f' in lemma_unsnoc_is_last y.nodes; lemma_snoc_unsnoc (reveal d.nodes, n); lemma_unsnoc_index y.nodes (length (y.nodes) - 2); lemma_unsnoc_length y.nodes; aux_unchanged_payload h0 h0' n y.nodes; aux_unchanged_payload h0' h1 t y.nodes; aux_unchanged_payload_transitive h0 h0' h1 y.nodes; y)
false
Hacl.Spec.Bignum.Exponentiation.fst
Hacl.Spec.Bignum.Exponentiation.bn_check_mod_exp
val bn_check_mod_exp: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> res:limb t{ let b = bn_v n % 2 = 1 && 1 < bn_v n && bn_v b < pow2 bBits && bn_v a < bn_v n in v res == (if b then v (ones t SEC) else v (zeros t SEC))}
val bn_check_mod_exp: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> res:limb t{ let b = bn_v n % 2 = 1 && 1 < bn_v n && bn_v b < pow2 bBits && bn_v a < bn_v n in v res == (if b then v (ones t SEC) else v (zeros t SEC))}
let bn_check_mod_exp #t #len n a bBits b = let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then begin BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits end else begin Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC end in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 46, "start_col": 0, "start_line": 24 }
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module LE = Lib.Exponentiation module SE = Spec.Exponentiation module E = Hacl.Spec.Exponentiation.Lemmas module M = Hacl.Spec.Montgomery.Lemmas module BN = Hacl.Spec.Bignum module BM = Hacl.Spec.Bignum.Montgomery module BI = Hacl.Spec.Bignum.ModInvLimb module ME = Hacl.Spec.Bignum.MontExponentiation module AE = Hacl.Spec.Bignum.AlmostMontExponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.AlmostMontExponentiation.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
n: Hacl.Spec.Bignum.Definitions.lbignum t len -> a: Hacl.Spec.Bignum.Definitions.lbignum t len -> bBits: Lib.IntTypes.size_nat -> b: Hacl.Spec.Bignum.Definitions.lbignum t (Hacl.Spec.Bignum.Definitions.blocks0 bBits (Lib.IntTypes.bits t)) -> res: Hacl.Spec.Bignum.Definitions.limb t { let b = Hacl.Spec.Bignum.Definitions.bn_v n % 2 = 1 && 1 < Hacl.Spec.Bignum.Definitions.bn_v n && Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 bBits && Hacl.Spec.Bignum.Definitions.bn_v a < Hacl.Spec.Bignum.Definitions.bn_v n in Lib.IntTypes.v res == (match b with | true -> Lib.IntTypes.v (Lib.IntTypes.ones t Lib.IntTypes.SEC) | _ -> Lib.IntTypes.v (Lib.IntTypes.zeros t Lib.IntTypes.SEC)) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.unit", "Lib.IntTypes.logand_lemma", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Amp_Dot", "Prims._assert", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.bool", "Prims.op_LessThan", "Hacl.Spec.Bignum.bn_lt_mask_lemma", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.bn_lt_mask", "Prims.op_LessThanOrEqual", "Prims.pow2", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.bn_lt_pow2_mask", "Hacl.Spec.Bignum.bn_lt_pow2_mask_lemma", "Lib.IntTypes.ones", "FStar.Math.Lemmas.pow2_le_compat", "Hacl.Spec.Bignum.Definitions.blocks", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims.eq2", "Lib.IntTypes.range", "Prims.op_AmpAmp", "Prims.op_Modulus", "Lib.IntTypes.zeros", "Hacl.Spec.Bignum.Montgomery.bn_check_modulus", "Lib.IntTypes.range_t" ]
[]
false
false
false
false
false
let bn_check_mod_exp #t #len n a bBits b =
let pbits = bits t in let m0 = BM.bn_check_modulus n in bn_eval_bound b (blocks0 bBits pbits); let m1 = if bBits < pbits * blocks0 bBits pbits then (BN.bn_lt_pow2_mask_lemma b bBits; BN.bn_lt_pow2_mask b bBits) else (Math.Lemmas.pow2_le_compat bBits (pbits * blocks bBits pbits); ones t SEC) in assert (if v m1 = 0 then pow2 bBits <= bn_v b else bn_v b < pow2 bBits); let m2 = BN.bn_lt_mask a n in BN.bn_lt_mask_lemma a n; assert (if v m2 = 0 then bn_v a >= bn_v n else bn_v a < bn_v n); let m = m1 &. m2 in logand_lemma m1 m2; let r = m0 &. m in logand_lemma m0 m; r
false
EverCrypt.Ed25519.fst
EverCrypt.Ed25519.sign_expanded
val sign_expanded: signature:lbuffer uint8 64ul -> expanded_keys:lbuffer uint8 96ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> Stack unit (requires fun h -> live h signature /\ live h msg /\ live h expanded_keys /\ disjoint signature msg /\ disjoint signature expanded_keys) (ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\ as_seq h1 signature == Spec.Ed25519.sign_expanded (as_seq h0 (gsub expanded_keys 0ul 32ul)) (as_seq h0 (gsub expanded_keys 32ul 32ul)) (as_seq h0 (gsub expanded_keys 64ul 32ul)) (as_seq h0 msg))
val sign_expanded: signature:lbuffer uint8 64ul -> expanded_keys:lbuffer uint8 96ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> Stack unit (requires fun h -> live h signature /\ live h msg /\ live h expanded_keys /\ disjoint signature msg /\ disjoint signature expanded_keys) (ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\ as_seq h1 signature == Spec.Ed25519.sign_expanded (as_seq h0 (gsub expanded_keys 0ul 32ul)) (as_seq h0 (gsub expanded_keys 32ul 32ul)) (as_seq h0 (gsub expanded_keys 64ul 32ul)) (as_seq h0 msg))
let sign_expanded signature expanded_keys msg_len msg = Hacl.Ed25519.sign_expanded signature expanded_keys msg_len msg
{ "file_name": "providers/evercrypt/fst/EverCrypt.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 12, "start_col": 0, "start_line": 11 }
module EverCrypt.Ed25519 /// For now, only one implementation... to be improved in the future. let secret_to_public public_key private_key = Hacl.Ed25519.secret_to_public public_key private_key let expand_keys expanded_keys private_key = Hacl.Ed25519.expand_keys expanded_keys private_key
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Ed25519.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "EverCrypt.Ed25519.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> expanded_keys: Lib.Buffer.lbuffer Lib.IntTypes.uint8 96ul -> msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Hacl.Ed25519.sign_expanded", "Prims.unit" ]
[]
false
true
false
false
false
let sign_expanded signature expanded_keys msg_len msg =
Hacl.Ed25519.sign_expanded signature expanded_keys msg_len msg
false
EverCrypt.Ed25519.fst
EverCrypt.Ed25519.expand_keys
val expand_keys: expanded_keys:lbuffer uint8 96ul -> private_key:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h expanded_keys /\ live h private_key /\ disjoint expanded_keys private_key) (ensures fun h0 _ h1 -> modifies (loc expanded_keys) h0 h1 /\ (let public_key, s, prefix = Spec.Ed25519.expand_keys (as_seq h0 private_key) in as_seq h1 (gsub expanded_keys 0ul 32ul) == public_key /\ as_seq h1 (gsub expanded_keys 32ul 32ul) == s /\ as_seq h1 (gsub expanded_keys 64ul 32ul) == prefix))
val expand_keys: expanded_keys:lbuffer uint8 96ul -> private_key:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h expanded_keys /\ live h private_key /\ disjoint expanded_keys private_key) (ensures fun h0 _ h1 -> modifies (loc expanded_keys) h0 h1 /\ (let public_key, s, prefix = Spec.Ed25519.expand_keys (as_seq h0 private_key) in as_seq h1 (gsub expanded_keys 0ul 32ul) == public_key /\ as_seq h1 (gsub expanded_keys 32ul 32ul) == s /\ as_seq h1 (gsub expanded_keys 64ul 32ul) == prefix))
let expand_keys expanded_keys private_key = Hacl.Ed25519.expand_keys expanded_keys private_key
{ "file_name": "providers/evercrypt/fst/EverCrypt.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 9, "start_col": 0, "start_line": 8 }
module EverCrypt.Ed25519 /// For now, only one implementation... to be improved in the future. let secret_to_public public_key private_key = Hacl.Ed25519.secret_to_public public_key private_key
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Ed25519.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "EverCrypt.Ed25519.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
expanded_keys: Lib.Buffer.lbuffer Lib.IntTypes.uint8 96ul -> private_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Hacl.Ed25519.expand_keys", "Prims.unit" ]
[]
false
true
false
false
false
let expand_keys expanded_keys private_key =
Hacl.Ed25519.expand_keys expanded_keys private_key
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_inj
val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len)
val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len)
let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 168, "start_col": 0, "start_line": 158 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Lib.IntTypes.size_nat -> b1: Hacl.Spec.Bignum.Definitions.lbignum t len -> b2: Hacl.Spec.Bignum.Definitions.lbignum t len -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v b1 == Hacl.Spec.Bignum.Definitions.bn_v b2) (ensures Lib.Sequence.equal b1 b2) (decreases len)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_Equality", "Prims.int", "Prims.bool", "FStar.Seq.Properties.lemma_split", "Hacl.Spec.Bignum.Definitions.limb", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.bn_eval1", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_eval_inj #t len b1 b2 =
if len = 0 then () else (bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1)
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_split_i_aux
val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b)
val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b)
let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; }
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 117, "start_col": 0, "start_line": 106 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
p: Prims.nat -> a: Prims.nat -> b: Prims.nat -> c: Prims.nat -> i: Prims.nat -> FStar.Pervasives.Lemma (requires Prims.pow2 p * c == a - b) (ensures Prims.pow2 (p * (i + 1)) * c == Prims.pow2 (p * i) * a - Prims.pow2 (p * i) * b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Addition", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.pow2_plus", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.distributivity_sub_right" ]
[]
false
false
true
false
false
let bn_eval_split_i_aux p a b c i =
calc ( == ) { pow2 (p * (i + 1)) * c; ( == ) { Math.Lemmas.pow2_plus (p * i) p } (pow2 (p * i) * pow2 p) * c; ( == ) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); ( == ) { () } pow2 (p * i) * (a - b); ( == ) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; }
false
DoublyLinkedList.fst
DoublyLinkedList.dll_remove_tail
val dll_remove_tail (#t: Type) (d: dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (length d.nodes > 0))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_buffer (d.ltail @ h0).blink) h0 h1 /\ _aux_fp_split_by_node d y d.ltail /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == fst (unsnoc (reveal d.nodes))))
val dll_remove_tail (#t: Type) (d: dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (length d.nodes > 0))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_buffer (d.ltail @ h0).blink) h0 h1 /\ _aux_fp_split_by_node d y d.ltail /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == fst (unsnoc (reveal d.nodes))))
let dll_remove_tail (#t:Type) (d:dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (length d.nodes > 0))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_buffer (d.ltail@h0).blink) h0 h1 /\ _aux_fp_split_by_node d y d.ltail /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == fst (unsnoc (reveal d.nodes)))) = let h0 = ST.get () in let e = d.ltail in let e1 = (!*e).blink in lemma_dll_links_contained h0 d (length d.nodes - 1); lemma_unsnoc_is_last d.nodes; if is_null e1 then ( _lemma_only_head_can_point_left_to_null h0 e d.nodes; empty_list ) else ( extract_nodelist_contained h0 d.nodes (length (d.nodes) - 2); extract_nodelist_conn h0 d.nodes (length (d.nodes) - 2); // assert (e == (reveal d.nodes).[length (reveal d.nodes) - 1]); // assert (e1 == (reveal d.nodes).[length (reveal d.nodes) - 2]); !=|> e1; let h1 = ST.get () in let f = tot_dll_to_fragment_split h0 d e1 e in let Frag2 p1 p2 = f in lemma_snoc_length (reveal p1.pnodes, e); // assert (reveal p1.pnodes == fst (unsnoc (reveal d.nodes))); let f' = Frag1 p1 in piece_remains_valid_f h0 h1 p1; let y = tot_defragmentable_fragment_to_dll h1 f' in aux_unchanged_payload h0 h1 e1 (d.nodes); // assert (reveal y.nodes == reveal p1.pnodes); y )
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 1833, "start_col": 0, "start_line": 1797 }
(* Copyright 2008-2019 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 DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl let dll_valid (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d let piece_valid (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = piece_ghostly_connections p /\ piece_contained h0 p /\ piece_aa p /\ piece_conn h0 p let fragment_valid (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_ghostly_connections f /\ fragment_contained h0 f /\ fragment_aa f /\ fragment_conn h0 f /// Talk about payloads of nodes remaining constant let unchanged_node_val h0 h1 n = (h0 `contains` n ==> ((n@h0).p == (n@h1).p /\ h1 `contains` n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:nodelist 'a) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Useful operations on nodes let ( =|> ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ b@h0 == b@h1 /\ (a@h1) |>> b)) = a *= { !*a with flink = b } let ( <|= ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer b) h0 h1 /\ a@h0 == a@h1 /\ unchanged_node_val h0 h1 b /\ (b@h0).flink == (b@h1).flink /\ a <<| (b@h1))) = b *= { !*b with blink = a } let ( !=|> ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ (a@h1).flink == null)) = a *= { !*a with flink = null } let ( !<|= ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).flink == (a@h1).flink /\ (a@h1).blink == null)) = a *= { !*a with blink = null } /// Extraction lemmas: these allow one to use one of the properties /// above, which are defined inductively, to get the property at one /// of the latter elements of the list. let rec extract_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_contained h0 nl)) (ensures (h0 `contains` nl.[i])) = match i with | 0 -> () | _ -> extract_nodelist_contained h0 (tl nl) (i - 1) let rec extract_nodelist_fp0 (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer nl.[i]))) = match i with | 0 -> () | _ -> extract_nodelist_fp0 (tl nl) (i - 1) let rec extract_nodelist_aa_r (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_r nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 right))) = match i with | 0 -> () | _ -> extract_nodelist_aa_r (tl nl) (i - 1) let rec extract_nodelist_aa_l (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_l nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 left))) (decreases (length nl)) = if i = length nl - 1 then () else ( let a, b = unsnoc nl in lemma_unsnoc_length nl; let left, n, right = split3 nl i in lemma_unsnoc_split3 nl i; // assert (append (left) (n :: (fst (unsnoc right))) == a); extract_nodelist_aa_l a i; lemma_split3_unsnoc nl i ) let rec extract_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl - 1}) : Lemma (requires (nodelist_conn h0 nl)) (ensures ( (nl.[i]@h0 |>> nl.[i+1]) /\ (nl.[i] <<| nl.[i+1]@h0))) (decreases (length nl)) = match i with | 0 -> () | _ -> extract_nodelist_conn h0 (tl nl) (i - 1) /// Validity is maintained upon breaking the lists, via (hd :: tl) let rec nodelist_remains_aa_l (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa_l nl /\ length nl > 0)) (ensures (nodelist_aa_l (tl nl))) (decreases (length nl)) [SMTPat (nodelist_aa_l (tl nl))] = match nl with | [n] -> () | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; let ns', n' = unsnoc (tl nl) in // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (n' == n); // assert (ns' == tl ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns')); nodelist_remains_aa_l ns (* Rest of the validity predicates are held trivially due to their direction of definition *) /// Properties maintained upon breaking the list, via unsnoc let rec fst_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> fst_unsnoc_nodelist_fp0 ns let rec snd_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> snd_unsnoc_nodelist_fp0 ns let rec fst_unsnoc_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_contained h0 nl /\ length nl > 0)) (ensures (nodelist_contained h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_contained h0 (tl nl) let rec fst_unsnoc_nodelist_aa (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa nl /\ length nl > 0)) (ensures (nodelist_aa (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_aa (tl nl); // assert (nodelist_aa_l (fst (unsnoc nl))); let n :: ns = fst (unsnoc nl) in Mod.loc_disjoint_includes (Mod.loc_buffer n) (nodelist_fp0 (tl nl)) (Mod.loc_buffer n) (nodelist_fp0 ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (nodelist_aa_r (fst (unsnoc nl))); () let rec fst_unsnoc_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_conn h0 nl /\ length nl > 0)) (ensures (nodelist_conn h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_conn h0 (tl nl) let fst_unsnoc_nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_valid h0 nl /\ length nl > 0)) (ensures (nodelist_valid h0 (fst (unsnoc nl)))) = fst_unsnoc_nodelist_contained h0 nl; fst_unsnoc_nodelist_aa nl; fst_unsnoc_nodelist_conn h0 nl /// Footprints are included, even upon breaking nodelist even further let rec nodelist_includes_r_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let _, a = splitAt i nl in let _, b = splitAt j nl in Mod.loc_includes (nodelist_fp0 a) (nodelist_fp0 b))) (decreases (j - i)) = if i = j then () else ( let temp, a = splitAt i nl in lemma_splitAt nl temp a i; let temp, b = splitAt j nl in lemma_splitAt nl temp b j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (tl a == b); () ) else ( nodelist_includes_r_fp0 nl i (j - 1); nodelist_includes_r_fp0 nl (j - 1) j; let temp, c = splitAt (j - 1) nl in lemma_splitAt nl temp c (j - 1); Mod.loc_includes_trans (nodelist_fp0 a) (nodelist_fp0 c) (nodelist_fp0 b) ) ) let rec nodelist_includes_l_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let a, _ = splitAt i nl in let b, _ = splitAt j nl in Mod.loc_includes (nodelist_fp0 b) (nodelist_fp0 a))) (decreases (j - i)) = if i = j then () else ( let a, a' = splitAt i nl in lemma_splitAt nl a a' i; let b, b' = splitAt j nl in lemma_splitAt nl b b' j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (b == append a [hd a']); lemma_unsnoc_append a [hd a']; // assert (snd (unsnoc b) == hd a'); // assert (fst (unsnoc b) == a); fst_unsnoc_nodelist_fp0 b ) else ( nodelist_includes_l_fp0 nl i (j - 1); nodelist_includes_l_fp0 nl (j - 1) j; let c, c' = splitAt (j - 1) nl in lemma_splitAt nl c c' (j - 1); Mod.loc_includes_trans (nodelist_fp0 b) (nodelist_fp0 c) (nodelist_fp0 a) ) ) /// Total conversions between fragments, pieces, and dlls let tot_dll_to_piece (#t:Type) (h0:heap) (d:nonempty_dll t{dll_valid h0 d}) : Tot (p:piece t{piece_valid h0 p}) = { phead = d.lhead ; ptail = d.ltail ; pnodes = d.nodes } let tot_dll_to_fragment (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d /\ d.lhead =!= null}) : Tot (f:fragment t{fragment_valid h0 f}) = Frag1 (tot_dll_to_piece h0 d) let tot_piece_to_dll (#t:Type) (h0:heap) (p:piece t{ piece_valid h0 p /\ (p.phead@h0).blink == null /\ (p.ptail@h0).flink == null}) : Tot (d:dll t{dll_valid h0 d}) = { lhead = p.phead ; ltail = p.ptail ; nodes = p.pnodes } (* The conversions piece<->fragment are trivial *) /// Properties maintained when appending nodelists let rec nodelist_append_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) (ensures (nodelist_contained h0 (append nl1 nl2))) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_append_contained h0 nl1' nl2 let rec nodelist_append_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ( loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)))) = match nl1 with | [] -> () | n :: nl1' -> nodelist_append_fp0 nl1' nl2; // assert (loc_equiv // (nodelist_fp0 (append nl1' nl2)) // (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))); // assert (loc_equiv // (nodelist_fp0 nl1) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1'))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1')) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); loc_equiv_trans (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); () #set-options "--z3rlimit 20" let rec nodelist_append_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l nl1 /\ nodelist_aa_l nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_l (append nl1 nl2))) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; nodelist_append_fp0 nl1 nl2'; // assert (nodelist_aa_l nl2'); assert (Mod.loc_includes (nodelist_fp0 nl2) (nodelist_fp0 nl2')); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); lemma_unsnoc_is_last nl2; assert (Mod.loc_includes (nodelist_fp0 nl2) (Mod.loc_buffer n)); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl1)); // assert (loc_equiv (nodelist_fp0 (append nl1 nl2')) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2'))); nodelist_append_aa_l nl1 nl2'; // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (append nl1 nl2'))); lemma_unsnoc_append nl1 nl2; // assert (append nl1 nl2' == fst (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (fst (unsnoc (append nl1 nl2))))); () #reset-options let rec nodelist_append_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r nl1 /\ nodelist_aa_r nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_r (append nl1 nl2))) = match nl1 with | [] -> () | _ -> nodelist_append_fp0 (tl nl1) nl2; nodelist_append_aa_r (tl nl1) nl2 let nodelist_append_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa (append nl1 nl2))) = nodelist_append_aa_l nl1 nl2; nodelist_append_aa_r nl1 nl2 let rec nodelist_append_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_conn h0 (append nl1 nl2))) = match nl1 with | [_] -> () | _ -> nodelist_append_conn h0 (tl nl1) nl2 let nodelist_append_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_valid h0 (append nl1 nl2))) = nodelist_append_contained h0 nl1 nl2; nodelist_append_aa nl1 nl2; nodelist_append_conn h0 nl1 nl2 /// Useful property for for piece merging let loc_includes_union_r_inv (a b c:Mod.loc) : Lemma (requires (Mod.loc_includes a (Mod.loc_union b c))) (ensures (Mod.loc_includes a b /\ Mod.loc_includes a c)) = Mod.loc_includes_union_l b c b; Mod.loc_includes_trans a (Mod.loc_union b c) b; Mod.loc_includes_union_l b c c; Mod.loc_includes_trans a (Mod.loc_union b c) c /// Piece merging #set-options "--z3rlimit 10" val piece_merge (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Pure (piece t) (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (fun p -> (piece_valid h0 p) /\ (reveal p.pnodes == p1.pnodes `append` p2.pnodes))) let piece_merge #t h0 p1 p2 = let p = { phead = p1.phead ; ptail = p2.ptail ; pnodes = p1.pnodes ^@^ p2.pnodes } in lemma_append_last p1.pnodes p2.pnodes; nodelist_append_valid h0 p1.pnodes p2.pnodes; p #reset-options let piece_merge_fp0 (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Lemma (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (loc_equiv (piece_fp0 (piece_merge h0 p1 p2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)))) = let p = piece_merge h0 p1 p2 in let n1, n2, n = reveal p1.pnodes, reveal p2.pnodes, reveal p.pnodes in nodelist_append_fp0 n1 n2; // assert (loc_equiv (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); // assert (hd n1 == p1.phead); // assert (Mod.loc_includes (nodelist_fp0 n1) (Mod.loc_buffer p1.phead)); // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.phead)); // assert (last n2 == p2.ptail); extract_nodelist_fp0 n2 (length n2 - 1); lemma_unsnoc_is_last n2; // assert (Mod.loc_includes (nodelist_fp0 n2) (Mod.loc_buffer p2.ptail)); extract_nodelist_fp0 n (length n - 1); lemma_unsnoc_is_last n; // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.ptail)); loc_includes_union_r_inv (nodelist_fp0 n) (nodelist_fp0 n1) (nodelist_fp0 n2); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n1)); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n2)); // // assert (loc_equiv (nodelist_fp0 n) (piece_fp0 p)); extract_nodelist_fp0 n1 (length n1 - 1); lemma_unsnoc_is_last n1; // assert (loc_equiv (nodelist_fp0 n1) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 n2) (piece_fp0 p2)); // // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); Mod.loc_includes_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); Mod.loc_includes_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (Mod.loc_includes (piece_fp0 p) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // // assert (Mod.loc_includes (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (nodelist_fp0 n)); loc_equiv_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); loc_equiv_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); loc_equiv_trans (piece_fp0 p) (nodelist_fp0 n) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)) /// Fragment merging to a dll let rec fragment_defragmentable (#t:Type) (h0:heap) (f:fragment t{fragment_valid h0 f}) : GTot Type0 = let aux (p1 p2:(p:piece t{piece_valid h0 p})) = let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\(a <<| b@h0) in match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> aux p1 p2 | Frag3 p1 p2 p3 -> aux p1 p2 /\ aux p2 p3 let single_piece_fragment_valid (#t:Type) (h0:heap) (p:piece t) : Lemma (requires (piece_valid h0 p)) (ensures (fragment_valid h0 (Frag1 p))) = () #set-options "--z3rlimit 40 --initial_ifuel 2" let tot_defragmentable_fragment_to_dll (#t:Type) (h0:heap) (f:fragment t{ fragment_valid h0 f /\ fragment_defragmentable h0 f /\ (fragment_length f > 0 ==> (let a, b = match f with | Frag1 p1 -> p1, p1 | Frag2 p1 p2 -> p1, p2 | Frag3 p1 _ p3 -> p1, p3 in ((a.phead@h0).blink == null) /\ ((b.ptail@h0).flink == null))) }) : Tot (d:dll t{dll_valid h0 d /\ dll_fp0 d `loc_equiv` fragment_fp0 f /\ (reveal d.nodes == ( match f with | Frag0 -> [] | Frag1 p1 -> reveal p1.pnodes | Frag2 p1 p2 -> reveal p1.pnodes `append` reveal p2.pnodes | Frag3 p1 p2 p3 -> reveal p1.pnodes `append` reveal p2.pnodes `append` reveal p3.pnodes)) }) = match f with | Frag0 -> empty_list | Frag1 p1 -> tot_piece_to_dll h0 p1 | Frag2 p1 p2 -> piece_merge_fp0 h0 p1 p2; tot_piece_to_dll h0 (piece_merge h0 p1 p2) | Frag3 p1 p2 p3 -> piece_merge_fp0 h0 p1 p2; let p' = piece_merge h0 p1 p2 in piece_merge_fp0 h0 p' p3; tot_piece_to_dll h0 (piece_merge h0 p' p3) #reset-options /// Properties of nodelists maintained upon splitting nodelists let rec nodelist_split_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 (append nl1 nl2))) (ensures (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_split_contained h0 nl1' nl2 let rec nodelist_split_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = match nl1 with | [] | [_] -> () | _ -> match nl2 with | [] -> () | _ -> // assert (length nl1 > 1); // assert (length nl2 > 0); nodelist_split_fp0 (tl nl1) nl2; append_length nl1 nl2; nodelist_includes_r_fp0 (tl (append nl1 nl2)) 0 (length nl1 - 1); // assert (snd (splitAt 0 (tl (append nl1 nl2))) == tl (append nl1 nl2)); // assert (snd (splitAt (length nl1 - 1) (tl (append nl1 nl2))) == snd (splitAt (length nl1) (append nl1 nl2))); lemma_append_splitAt nl1 nl2; // assert (snd (splitAt (length nl1) (append nl1 nl2)) == nl2); // assert (Mod.loc_includes (nodelist_fp0 (tl (append nl1 nl2))) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl (append nl1 nl2)))); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (nodelist_fp0 (tl nl1)) (nodelist_fp0 nl2)); Mod.loc_disjoint_union_r (nodelist_fp0 nl2) (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1)); // assert (Mod.loc_disjoint (Mod.loc_union (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1))) (nodelist_fp0 nl2)); () #set-options "--z3rlimit 30" let rec nodelist_split_fp0_equiv (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ((loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2))))) = match nl1 with | [] -> () | n :: ns -> nodelist_split_fp0_equiv ns nl2; assert (loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2)))); // OBSERVE assert (loc_equiv (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns)) (nodelist_fp0 nl2))) // OBSERVE let rec nodelist_split_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l (append nl1 nl2))) (ensures (nodelist_aa_l nl1 /\ nodelist_aa_l nl2)) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; lemma_unsnoc_append nl1 nl2; // assert (nodelist_aa_l (append nl1 nl2)); // assert (nodelist_aa_l (append nl1 nl2')); nodelist_split_aa_l nl1 nl2'; // assert (nodelist_aa_l nl2'); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc nl2)); nodelist_append_fp0 nl1 nl2'; // assert (Mod.loc_includes (nodelist_fp0 (append nl1 nl2')) (nodelist_fp0 nl2')); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); // assert (nodelist_aa_l nl2); () #reset-options let rec nodelist_split_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (nodelist_aa_r nl1 /\ nodelist_aa_r nl2)) = match nl1 with | [] -> () | _ -> nodelist_split_aa_r (tl nl1) nl2; nodelist_append_fp0 (tl nl1) nl2 let nodelist_split_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa (append nl1 nl2))) (ensures (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = nodelist_split_fp0 nl1 nl2; nodelist_split_aa_l nl1 nl2; nodelist_split_aa_r nl1 nl2 let rec nodelist_split_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires ( (nodelist_conn h0 (append nl1 nl2)) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = match nl1 with | [_] -> () | _ -> nodelist_split_conn h0 (tl nl1) nl2 let nodelist_split_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 (append nl1 nl2) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = nodelist_split_contained h0 nl1 nl2; nodelist_split_aa nl1 nl2; nodelist_split_conn h0 nl1 nl2 /// Useful lemma to convert from dll_fp0 or piece_fp0 to nodelist_fp0 /// and vice-versa let dll_fp0_is_nodelist_fp0 (#t:Type) (d:dll t) : Lemma (requires (dll_ghostly_connections d)) (ensures (loc_equiv (dll_fp0 d) (nodelist_fp0 d.nodes))) = if length d.nodes > 0 then lemma_unsnoc_is_last d.nodes else () let piece_fp0_is_nodelist_fp0 (#t:Type) (p:piece t) : Lemma (requires (piece_ghostly_connections p)) (ensures (loc_equiv (piece_fp0 p) (nodelist_fp0 p.pnodes))) = lemma_unsnoc_is_last (reveal p.pnodes) /// Tot dll to fragment, with splitting #set-options "--z3rlimit 60 --initial_fuel 8 --initial_ifuel 1" let tot_dll_to_fragment_split (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d}) (n1 n2:pointer (node t)) : Pure (fragment t) (requires ( n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1@h0 |>> n2 /\ n1 <<| n2@h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == reveal p1.pnodes `append` reveal p2.pnodes))) = let split_nodes = elift2_p split_using d.nodes (hide n2) in lemma_split_using d.nodes n2; let l1 = elift1 fst split_nodes in let l2 = elift1 snd split_nodes in let p1 = { phead = d.lhead ; ptail = n1 ; pnodes = l1 } in let p2 = { phead = n2 ; ptail = d.ltail ; pnodes = l2 } in let f = Frag2 p1 p2 in dll_fp0_is_nodelist_fp0 d; // assert (loc_equiv (dll_fp0 d) (nodelist_fp0 (reveal d.nodes))); nodelist_split_fp0_equiv l1 l2; nodelist_split_valid h0 l1 l2; lemma_unsnoc_is_last l1; lemma_unsnoc_is_last l2; lemma_unsnoc_is_last (reveal d.nodes); // assert (piece_ghostly_connections p1); // assert ( n2 == hd (reveal l2) ); lemma_append_last l1 l2; // assert ( last (reveal l2) == last (append (reveal l1) (reveal l2)) ); // assert ( d.ltail == last (reveal l2) ); // assert (piece_ghostly_connections p2); // assert (fragment_ghostly_connections f); // assert (nodelist_contained h0 (reveal p1.pnodes)); // assert (nodelist_contained h0 (reveal p2.pnodes)); extract_nodelist_contained h0 l1 (length l1 - 1); // assert (h0 `contains` p1.ptail); // assert (fragment_contained h0 f); // assert (nodelist_aa (reveal p1.pnodes)); // assert (nodelist_aa (reveal p2.pnodes)); piece_fp0_is_nodelist_fp0 p1; piece_fp0_is_nodelist_fp0 p2; // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2)))); // assert (loc_equiv (nodelist_fp0 (reveal l1)) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 (reveal l2)) (piece_fp0 p2)); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2))) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); loc_equiv_trans (dll_fp0 d) (Mod.loc_union (nodelist_fp0 l1) (nodelist_fp0 l2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // assert (Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)); // assert (fragment_aa f); // assert (nodelist_conn h0 (reveal p1.pnodes)); // assert (nodelist_conn h0 (reveal p2.pnodes)); // assert (fragment_conn h0 f); f #reset-options /// Creating a dll from a single node. Pure and ST forms of this. let tot_node_to_dll (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (dll t) (requires ( (h0 `contains` n) /\ (((n@h0).flink == null)) /\ ((n@h0).blink == null))) (ensures (fun d -> dll_valid h0 d)) = { lhead = n ; ltail = n ; nodes = ~. n } let singleton_dll (#t:Type) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (h0 `contains` n))) (ensures (fun h0 d h1 -> Mod.modifies (Mod.loc_buffer n) h0 h1 /\ dll_valid h1 d /\ unchanged_node_vals h0 h1 d.nodes /\ reveal d.nodes == [n])) = !=|> n; !<|= n; tot_node_to_dll (ST.get ()) n /// Creating a piece from a single node. let tot_node_to_piece (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (piece t) (requires ( (h0 `contains` n))) (ensures (fun p -> piece_valid h0 p)) = { phead = n ; ptail = n ; pnodes = ~. n } /// Getting the "tail" of a piece let tot_piece_tail (#t:Type) (h0:heap) (p:piece t) (n:pointer (node t)) : Pure (piece t) (requires ( (piece_valid h0 p) /\ (n == (((p.phead)@h0).flink)) /\ (length p.pnodes > 1))) (ensures (fun q -> (piece_valid h0 q) /\ (reveal q.pnodes) == tl p.pnodes)) = { phead = n ; ptail = p.ptail ; pnodes = elift1_p (tot_to_gtot tl) p.pnodes } /// If a dll is valid, then both the forward and backward links of /// each of the nodes are contained in the heap, and disjoint from /// each other let lemma_dll_links_contained (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in (h0 `contains` (nodes.[i]@h0).flink) /\ (h0 `contains` (nodes.[i]@h0).blink))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else extract_nodelist_contained h0 nl (i - 1)); (if i = length nl - 1 then () else extract_nodelist_contained h0 nl (i + 1)); lemma_unsnoc_is_last nl #set-options "--z3rlimit 10 --initial_ifuel 2" let lemma_dll_links_disjoint (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in let left = (nodes.[i]@h0).blink in let right = (nodes.[i]@h0).flink in Mod.loc_disjoint (Mod.loc_buffer left) (Mod.loc_buffer right))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> lemma_unsnoc_length nl; let node_split = splitAt i nl in lemma_splitAt nl (fst node_split) (snd node_split) i; lemma_splitAt_index_hd i nl; let l1, x :: l2 = node_split in (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else ( if i = length nl - 1 then (lemma_unsnoc_is_last nl) else ( lemma_unsnoc_is_last l1; let left = last l1 in let right = hd l2 in lemma_splitAt_reindex_left i nl (length l1 - 1); // assert (left == (nl.[i]@h0).blink); lemma_splitAt_reindex_right i nl 1; // assert (right == (nl.[i]@h0).flink); nodelist_split_aa l1 (x :: l2); // assert (Mod.loc_disjoint (nodelist_fp0 l1) (nodelist_fp0 l2)); assert (Mod.loc_includes (nodelist_fp0 l1) (Mod.loc_buffer left)); // OBSERVE assert (Mod.loc_includes (nodelist_fp0 l2) (Mod.loc_buffer right)); // OBSERVE () ))) #reset-options /// When something unrelated to a XYZ is changed, the XYZ itself shall /// remain valid let rec nodelist_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (nl:nodelist t) : Lemma (requires ( (nodelist_valid h0 nl) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (nodelist_fp0 nl)))) (ensures (nodelist_valid h1 nl)) = match nl with | [] -> () | _ -> nodelist_remains_valid h0 h1 loc (tl nl) let piece_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (piece_fp0 p)))) (ensures (piece_valid h1 p)) = nodelist_remains_valid h0 h1 loc p.pnodes /// When outward facing pointers of ends of pieces are modified, they /// still remain valid #set-options "--z3rlimit 20" let piece_remains_valid_b (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.phead) h0 h1) /\ (h1 `contains` p.phead) /\ (p.phead@h0).flink == (p.phead@h1).flink)) (ensures (piece_valid h1 p) /\ (p.ptail@h0).flink == (p.ptail@h1).flink) = let nodes = p.pnodes in if length nodes > 1 then ( nodelist_includes_r_fp0 nodes 1 (length nodes - 1); lemma_unsnoc_is_last nodes; // assert (p.ptail == nodes.[length nodes - 1]); // assert (p.ptail@h0 == p.ptail@h1); // assert (h1 `contains` p.ptail); // assert (Mod.loc_disjoint (Mod.loc_buffer p.phead) (nodelist_fp0 (tl nodes))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.phead) (tl nodes) ) else () let piece_remains_valid_f (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1) /\ (h1 `contains` p.ptail) /\ (p.ptail@h0).blink == (p.ptail@h1).blink)) (ensures (piece_valid h1 p) /\ (p.phead@h0).blink == (p.phead@h1).blink) = let nodes = reveal p.pnodes in if length nodes > 1 then ( fst_unsnoc_nodelist_valid h0 nodes; // assert (nodelist_valid h0 (fst (unsnoc nodes))); lemma_unsnoc_is_last nodes; // assert (Mod.loc_disjoint (Mod.loc_buffer p.ptail) (nodelist_fp0 (fst (unsnoc nodes)))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.ptail) (fst (unsnoc nodes)); // assert (nodelist_contained h1 (fst (unsnoc nodes))); // assert (h1 `contains` (snd (unsnoc nodes))); nodelist_append_contained h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_contained h1 (reveal p.pnodes)); // assert (piece_contained h1 p); extract_nodelist_conn h0 nodes (length nodes - 2); // let nl1 = fst (unsnoc nodes) in lemma_unsnoc_is_last (fst (unsnoc nodes)); // assert (last nl1 == nl1.[length nl1 - 1]); // assert (last nl1 == nl1.[length nodes - 2]); lemma_unsnoc_index nodes (length nodes - 2); // assert (last nl1 == nodes.[length nodes - 2]); // assert ((last (fst (unsnoc nodes)))@h0 |>> (hd [snd (unsnoc nodes)])); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); // assert (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1); extract_nodelist_contained h0 nodes (length nodes - 2); // assert (h0 `contains` last (fst (unsnoc nodes))); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); assert (Mod.loc_includes (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer (last (fst (unsnoc nodes))))); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); lemma_snoc_length (unsnoc nodes); // assert ((last (fst (unsnoc nodes)))@h0 == (last (fst (unsnoc nodes)))@h1); // assert ((last (fst (unsnoc nodes)))@h1 |>> (hd [snd (unsnoc nodes)])); // assert ((last (fst (unsnoc nodes))) <<| (hd [snd (unsnoc nodes)])@h1); nodelist_append_conn h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_conn h1 (reveal p.pnodes)); // assert (piece_conn h1 p); // assert ((p.phead@h0).blink == (p.phead@h1).blink); () ) else () #reset-options /// Testing is a node is within a dll or not let node_not_in_dll (#t:Type) (h0:heap) (n:pointer (node t)) (d:dll t) = let m1 = Mod.loc_buffer n in let m2 = dll_fp0 d in Mod.loc_disjoint m1 m2 /// An empty dll has no nodes let _auto_empty_dll (#t:Type) (h0:heap) (d:dll t) : Lemma (requires (dll_valid h0 d /\ (d.lhead == null \/ d.ltail == null))) (ensures (reveal d.nodes == [])) [SMTPat (dll_valid h0 d); SMTPat (reveal d.nodes)] = () /// Be able to easily reason about unchanged payloads let rec aux_unchanged_payload #t h0 h1 n0 (nl:nodelist t) : Lemma (requires (Mod.modifies (Mod.loc_buffer n0) h0 h1 /\ (n0@h0).p == (n0@h1).p /\ (nodelist_aa_r nl) /\ (n0 `memP` nl \/ Mod.loc_disjoint (Mod.loc_buffer n0) (nodelist_fp0 nl)) )) (ensures (unchanged_node_vals h0 h1 nl)) (decreases (length nl)) = match nl with | [] -> () | n :: nl' -> aux_unchanged_payload h0 h1 n0 nl'; assert (n0 `memP` nl ==> (n == n0 \/ n0 `memP` nl')); let goal () = unchanged_node_val h0 h1 n in FStar.Classical.or_elim #_ #_ #goal (fun (_:unit{n0 `memP` nl}) -> FStar.Classical.or_elim #_ #_ #goal (fun (_:unit{n == n0}) -> ()) (fun (_:unit{n0 `memP` nl'}) -> let i = nl' `index_of` n0 in extract_nodelist_fp0 nl' i)) (fun (_:unit{Mod.loc_disjoint (Mod.loc_buffer n0) (nodelist_fp0 nl)}) -> ()) let rec aux_unchanged_payload_nomod #t h0 h1 (nl:nodelist t) : Lemma (requires (Mod.modifies Mod.loc_none h0 h1)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: nl' -> aux_unchanged_payload_nomod h0 h1 nl' let rec aux_unchanged_payload_transitive #t h0 h1 h2 (nl:nodelist t) : Lemma (requires (unchanged_node_vals h0 h1 nl /\ unchanged_node_vals h1 h2 nl)) (ensures (unchanged_node_vals h0 h2 nl)) = match nl with | [] -> () | _ :: nl' -> aux_unchanged_payload_transitive h0 h1 h2 nl' let rec aux_unchanged_payload_append #t h0 h1 (nl1 nl2:nodelist t) : Lemma (requires (unchanged_node_vals h0 h1 nl1 /\ unchanged_node_vals h0 h1 nl2)) (ensures (unchanged_node_vals h0 h1 (nl1 `append` nl2))) = match nl1 with | [] -> () | n :: nl' -> aux_unchanged_payload_append h0 h1 nl' nl2 /// Now for the actual ST operations that will be exposed :) #set-options "--z3rlimit 500 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head (#t:Type) (d:dll t) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.lhead)) h0 h1 /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == n :: reveal d.nodes)) = if is_null d.lhead then ( singleton_dll n ) else ( let h = d.lhead in // let h0 = ST.get () in !<|= n; n =|> h; let h0' = ST.get () in n <|= h; let h1 = ST.get () in // aux_unchanged_payload h0 h0' n d.nodes; aux_unchanged_payload h0' h1 h d.nodes; aux_unchanged_payload_transitive h0 h0' h1 d.nodes; // let Frag1 p1 = tot_dll_to_fragment h0 d in let p = tot_node_to_piece h0 n in let f' = Frag2 p p1 in // assert (fragment_valid h1 [p]); // assert (fragment_ghostly_connections f); // assert (length f = 1); // assert (h1 `contains` (hd f).phead); piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; // assert (piece_valid h0' (hd f)); piece_remains_valid_b h0' h1 p1; // assert (h1 `contains` (hd f).ptail); // assert (nodelist_contained h1 (reveal (hd f).pnodes)); // assert (piece_contained h1 (hd f)); // assert (fragment_contained h1 f); // assert (fragment_aa f); // assert (nodelist_conn h1 (reveal (f.[0]).pnodes)); // assert (fragment_conn h1 f); // assert (fragment_valid h1 f); // assert (fragment_valid h1 f'); // assert (fragment_defragmentable h1 f'); // assert (length f' > 0); // assert (is_null ((hd f').phead@h1).blink); // assert (is_null ((last f').ptail@h0).flink); // assert (is_null ((last f').ptail@h0').flink); // assert (is_null ((last f').ptail@h1).flink); let y = tot_defragmentable_fragment_to_dll h1 f' in // assert (dll_valid h1 y); y ) #reset-options #set-options "--z3rlimit 500 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail (#t:Type) (d:dll t) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) h0 h1 /\ (dll_fp0 y `loc_equiv` B.loc_union (dll_fp0 d) (Mod.loc_buffer n)) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == snoc (reveal d.nodes, n))) = if is_null d.lhead then ( singleton_dll n ) else ( let t = d.ltail in // let h0 = ST.get () in !=|> n; t <|= n; let h0' = ST.get () in lemma_dll_links_contained h0 d (length d.nodes - 1); lemma_unsnoc_is_last d.nodes; // assert (Mod.loc_disjoint (Mod.loc_buffer (t@h0).blink) (Mod.loc_buffer n)); t =|> n; let h1 = ST.get () in // let Frag1 p1 = tot_dll_to_fragment h0 d in let p = tot_node_to_piece h0 n in let f' = Frag2 p1 p in piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; piece_remains_valid_f h0' h1 p1; let y = tot_defragmentable_fragment_to_dll h1 f' in lemma_unsnoc_is_last y.nodes; lemma_snoc_unsnoc (reveal d.nodes, n); lemma_unsnoc_index y.nodes (length (y.nodes) - 2); lemma_unsnoc_length y.nodes; aux_unchanged_payload h0 h0' n y.nodes; aux_unchanged_payload h0' h1 t y.nodes; aux_unchanged_payload_transitive h0 h0' h1 y.nodes; y ) #reset-options let _l_insert_after (x0:'a) (l:list 'a{x0 `memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = lemma_split_using l x0; split_using l x0 in assert (x0 == x1); l1 `append` (x0 :: (x :: l2)) #set-options "--z3rlimit 1000 --initial_fuel 2 --initial_ifuel 1" let dll_insert_after (#t:Type) (d:dll t) (e:pointer (node t)) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) (Mod.loc_union (Mod.loc_buffer e) (Mod.loc_buffer (e@h0).flink))) h0 h1 /\ (dll_fp0 y `loc_equiv` B.loc_union (dll_fp0 d) (Mod.loc_buffer n)) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == _l_insert_after e d.nodes n)) = let h0 = ST.get () in // assert (length d.nodes > 0); lemma_dll_links_contained h0 d (d.nodes `index_of` e); extract_nodelist_contained h0 d.nodes (d.nodes `index_of` e); let e1 = (!*e).blink in let e2 = (!*e).flink in if is_null e2 then ( let y = dll_insert_at_tail d n in assume (reveal y.nodes == _l_insert_after e (reveal d.nodes) n); y ) else ( extract_nodelist_fp0 d.nodes (d.nodes `index_of` e); lemma_unsnoc_is_last d.nodes; extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e); extract_nodelist_fp0 d.nodes (d.nodes `index_of` e + 1); if not (is_null e1) then ( extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e - 1); extract_nodelist_fp0 d.nodes (d.nodes `index_of` e - 1) ) else (); e <|= n; // let h' = ST.get () in assert (h' `contains` e2); assert (Mod.loc_disjoint (Mod.loc_buffer n) (Mod.loc_buffer e2)); n =|> e2; let h0' = ST.get () in // assert (is_not_null e1 ==> e1 == (reveal d.nodes).[reveal d.nodes `index_of` e - 1]); // assert (is_not_null e1 ==> Mod.loc_includes (nodelist_fp0 (reveal d.nodes)) (Mod.loc_buffer e1)); // assert (is_not_null e1 ==> Mod.loc_disjoint (Mod.loc_buffer n) (Mod.loc_buffer e1)); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (Mod.loc_buffer e1)); Mod.modifies_buffer_elim e1 (Mod.loc_buffer n) h0 h0'; e =|> n; let h0'' = ST.get () in // assert (h0 `contains` e2); // assert (h0' `contains` e2); // assert (e2 == (reveal d.nodes).[reveal d.nodes `index_of` e + 1]); extract_nodelist_aa_r d.nodes (d.nodes `index_of` e); lemma_split3_r_hd d.nodes (d.nodes `index_of` e); lemma_split3_append d.nodes (d.nodes `index_of` e); lemma_split3_index d.nodes (d.nodes `index_of` e); lemma_split3_length d.nodes (d.nodes `index_of` e); // assert (Mod.loc_includes (nodelist_fp0 (reveal d.nodes)) (nodelist_fp0 (let _,_,z = split3 (reveal d.nodes) (reveal d.nodes `index_of` e) in z))); // assert (Mod.loc_includes (nodelist_fp0 (let _,_,z = split3 (reveal d.nodes) (reveal d.nodes `index_of` e) in z)) (Mod.loc_buffer e2)); // assert (Mod.loc_disjoint (Mod.loc_buffer e2) (Mod.loc_buffer e)); // assert (Mod.modifies (Mod.loc_buffer e) h0' h0''); Mod.modifies_buffer_elim e2 (Mod.loc_buffer e) h0' h0''; // assert (h0'' `contains` e2); n <|= e2; let h1 = ST.get () in // // assert (e `memP` reveal d.nodes); // assert (e2 `memP` reveal d.nodes); // assert (e@h0 |>> e2 /\ e <<| e2@h0); let f = tot_dll_to_fragment_split h0 d e e2 in // assert (length f = 2); let Frag2 p1 p3 = f in // assert ([p1 ; p3] == f); let p2 = tot_node_to_piece h0 n in let f' = Frag3 p1 p2 p3 in // assert (Mod.modifies (Mod.loc_buffer n) h0 h0'); // assert (piece_valid h0 p1); // assert (loc_equiv (dll_fp0 d) (fragment_fp0 f)); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (dll_fp0 d)); // assert (Mod.loc_includes (dll_fp0 d) (fragment_fp0 f)); // assert (Mod.loc_includes (fragment_fp0 f) (piece_fp0 p1)); Mod.loc_includes_trans (dll_fp0 d) (fragment_fp0 f) (piece_fp0 p1); // assert (Mod.loc_includes (dll_fp0 d) (piece_fp0 p1)); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (piece_fp0 p1)); piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; // assert (piece_valid h0 p3); Mod.loc_includes_trans (dll_fp0 d) (fragment_fp0 f) (piece_fp0 p3); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (piece_fp0 p3)); piece_remains_valid h0 h0' (Mod.loc_buffer n) p3; piece_remains_valid_f h0' h0'' p1; // assert (Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p3)); piece_remains_valid h0' h0'' (piece_fp0 p1) p3; piece_remains_valid h0'' h1 (piece_fp0 p3) p1; piece_remains_valid_b h0'' h1 p3; // assert ([p2 ; p3] == append [p2] [p3]); // assert (f' == append [p1] [p2 ; p3]); // // assert (fragment_valid h1 f'); assert (fragment_defragmentable h1 (Frag2 p2 p3)); // OBSERVE // assert (fragment_defragmentable h1 f'); // assert (length f' > 0); // assert (is_null ((hd f').phead@h1).blink); // lemma_unsnoc_is_last f'; // assert (last f' == p3); // assert (is_null ((last f').ptail@h1).flink); let y = tot_defragmentable_fragment_to_dll h1 f' in assume (n `memP` y.nodes); assume (e `memP` y.nodes); assume (e2 `memP` y.nodes); aux_unchanged_payload h0 h0' n y.nodes; aux_unchanged_payload h0' h0'' e y.nodes; aux_unchanged_payload h0'' h1 e2 y.nodes; aux_unchanged_payload_transitive h0 h0' h0'' y.nodes; aux_unchanged_payload_transitive h0 h0'' h1 y.nodes; assume (reveal y.nodes == _l_insert_after e (reveal d.nodes) n); y ) #reset-options let _l_insert_before (x0:'a) (l:list 'a{x0 `memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = split_using l x0 in l1 `append` (x :: l2) #set-options "--z3rlimit 50" let dll_insert_before (#t:Type) (d:dll t) (e:pointer (node t)) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) // this is needed due to using "after" // TODO: Figure out a way to remove it (Mod.loc_union (Mod.loc_buffer (e@h0).blink) (Mod.loc_buffer e)))) h0 h1 /\ (dll_fp0 y `loc_equiv` B.loc_union (dll_fp0 d) (Mod.loc_buffer n)) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == _l_insert_before e d.nodes n)) = let h0 = ST.get () in extract_nodelist_contained h0 d.nodes (d.nodes `index_of` e); let e1 = (!*e).blink in lemma_dll_links_contained h0 d (d.nodes `index_of` e); if is_null e1 then ( let y = dll_insert_at_head d n in assume (reveal y.nodes == _l_insert_before e d.nodes n); y ) else ( extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e - 1); let y = dll_insert_after d e1 n in assume (reveal y.nodes == _l_insert_before e (reveal d.nodes) n); y ) #reset-options unfold let _aux_fp_split_by_node (d0 d1:dll 'a) (n:pointer (node 'a)) = dll_fp0 d0 `loc_equiv` B.loc_union (dll_fp0 d1) (Mod.loc_buffer n) /\ dll_fp0 d1 `B.loc_disjoint` Mod.loc_buffer n #set-options "--z3rlimit 20" let dll_remove_head (#t:Type) (d:dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (length d.nodes > 0))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_buffer (d.lhead@h0).flink) h0 h1 /\ _aux_fp_split_by_node d y d.lhead /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == tl d.nodes)) = let h0 = ST.get () in let e = d.lhead in let e2 = (!*e).flink in if is_null e2 then ( empty_list ) else ( !<|= e2; let h1 = ST.get () in let f = tot_dll_to_fragment_split h0 d e e2 in let Frag2 p1 p2 = f in // assert (p1.phead == e); // assert (p1.ptail == e); let f' = Frag1 p2 in piece_remains_valid_b h0 h1 p2; let y = tot_defragmentable_fragment_to_dll h1 f' in aux_unchanged_payload h0 h1 e2 d.nodes; y ) #reset-options let rec _lemma_only_head_can_point_left_to_null (#t:Type) (h0:heap) (e:pointer (node t)) (l:nodelist t) : Lemma (requires (e `memP` l /\ (e@h0).blink == null /\ nodelist_conn h0 l)) (ensures (e == hd l)) = match l with | [_] -> () | _ -> FStar.Classical.or_elim #(e == hd l) #(e =!= hd l) #(fun () -> e == hd l) (fun _ -> ()) (fun _ -> _lemma_only_head_can_point_left_to_null h0 e (tl l); extract_nodelist_conn h0 l 0) let rec _lemma_only_tail_can_point_right_to_null (#t:Type) (h0:heap) (e:pointer (node t)) (l:nodelist t) : Lemma (requires (e `memP` l /\ (e@h0).flink == null /\ nodelist_conn h0 l)) (ensures (e == last l)) = match l with | [_] -> () | _ -> _lemma_only_tail_can_point_right_to_null h0 e (tl l) let rec _lemma_all_nodes_are_unique (#t:Type) (h0:heap) (l:nodelist t) (i j:nat) : Lemma (requires ( (nodelist_conn h0 l) /\ (i < length l) /\ (j < length l) /\ (((hd l)@h0).blink == null) /\ (index l i == index l j))) (ensures (i = j)) = match i, j with | 0, 0 -> () | 0, _ -> extract_nodelist_conn h0 l (j - 1) | _, 0 -> extract_nodelist_conn h0 l (i - 1) | _ -> extract_nodelist_conn h0 l (i - 1); extract_nodelist_conn h0 l (j - 1); _lemma_all_nodes_are_unique h0 l (i - 1) (j - 1) #set-options "--z3rlimit 50"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "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": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedList.dll t -> FStar.HyperStack.ST.StackInline (DoublyLinkedList.dll t)
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedList.dll", "DoublyLinkedList.empty_list", "Prims.unit", "DoublyLinkedList._lemma_only_head_can_point_left_to_null", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "Prims.bool", "DoublyLinkedList.piece", "DoublyLinkedList.aux_unchanged_payload", "Prims.l_and", "DoublyLinkedList.dll_valid", "DoublyLinkedList.loc_equiv", "DoublyLinkedList.dll_fp0", "DoublyLinkedList.fragment_fp0", "Prims.eq2", "Prims.list", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "Prims.Nil", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "FStar.List.Tot.Base.append", "DoublyLinkedList.tot_defragmentable_fragment_to_dll", "DoublyLinkedList.piece_remains_valid_f", "DoublyLinkedList.fragment", "DoublyLinkedList.Frag1", "FStar.List.Tot.Properties.lemma_snoc_length", "FStar.Pervasives.Native.Mktuple2", "DoublyLinkedList.tot_dll_to_fragment_split", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "DoublyLinkedList.op_Bang_Equals_Bar_Greater", "DoublyLinkedList.extract_nodelist_conn", "Prims.op_Subtraction", "FStar.List.Tot.Base.length", "DoublyLinkedList.extract_nodelist_contained", "LowStar.Monotonic.Buffer.is_null", "LowStar.Buffer.trivial_preorder", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedList.lemma_dll_links_contained", "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.__proj__Mknode__item__blink", "LowStar.BufferOps.op_Bang_Star", "DoublyLinkedList.__proj__Mkdll__item__ltail", "Prims.b2t", "Prims.op_GreaterThan", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.op_At", "DoublyLinkedList._aux_fp_split_by_node", "DoublyLinkedList.unchanged_node_vals", "FStar.Pervasives.Native.fst", "FStar.List.Tot.Base.unsnoc" ]
[]
false
true
false
false
false
let dll_remove_tail (#t: Type) (d: dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (length d.nodes > 0))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_buffer (d.ltail @ h0).blink) h0 h1 /\ _aux_fp_split_by_node d y d.ltail /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == fst (unsnoc (reveal d.nodes)))) =
let h0 = ST.get () in let e = d.ltail in let e1 = (!*e).blink in lemma_dll_links_contained h0 d (length d.nodes - 1); lemma_unsnoc_is_last d.nodes; if is_null e1 then (_lemma_only_head_can_point_left_to_null h0 e d.nodes; empty_list) else (extract_nodelist_contained h0 d.nodes (length (d.nodes) - 2); extract_nodelist_conn h0 d.nodes (length (d.nodes) - 2); !=|>e1; let h1 = ST.get () in let f = tot_dll_to_fragment_split h0 d e1 e in let Frag2 p1 p2 = f in lemma_snoc_length (reveal p1.pnodes, e); let f' = Frag1 p1 in piece_remains_valid_f h0 h1 p1; let y = tot_defragmentable_fragment_to_dll h1 f' in aux_unchanged_payload h0 h1 e1 (d.nodes); y)
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_mask_lemma
val bn_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> mask:limb t -> Lemma (requires v mask == v (ones t SEC) \/ v mask == 0) (ensures bn_v (map (logand mask) b) == (if v mask = 0 then 0 else bn_v b))
val bn_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> mask:limb t -> Lemma (requires v mask == v (ones t SEC) \/ v mask == 0) (ensures bn_v (map (logand mask) b) == (if v mask = 0 then 0 else bn_v b))
let bn_mask_lemma #t #len b mask = let res = map (logand mask) b in //assert (forall (i:nat{i < len}). res.[i] == (mask &. b.[i])); let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then 0 else v b.[i])) = logand_lemma mask b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then begin eq_intro res (create len (uint #t 0)); bn_eval_zeroes #t len len; assert (bn_v res == 0) end else eq_intro res b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 351, "start_col": 0, "start_line": 339 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i)) let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t)) let bn_eval_index #t #len b i = let pbits = bits t in calc (==) { bn_v b / pow2 (pbits * i) % pow2 pbits; (==) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; (==) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; (==) { bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i)) } bn_v (slice b i len) % pow2 pbits; (==) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; (==) { bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0 } v b.[i] % pow2 pbits; (==) { Math.Lemmas.modulo_lemma (v b.[i]) (pow2 pbits) } v b.[i]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[i]) val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k) let bn_eval_lt #t len a b k = let pbits = bits t in calc (==) { eval_ len b k - eval_ len a k; (==) { bn_eval_unfold_i b k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a k; (==) { bn_eval_unfold_i a k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a (k - 1) - v a.[k - 1] * pow2 (pbits * (k - 1)); (==) { Math.Lemmas.distributivity_sub_left (v b.[k - 1]) (v a.[k - 1]) (pow2 (pbits * (k - 1))) } eval_ len b (k - 1) - eval_ len a (k - 1) + (v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)); }; bn_eval_bound a (k - 1); bn_eval_bound b (k - 1); assert (eval_ len b (k - 1) - eval_ len a (k - 1) > - pow2 (pbits * (k - 1))); assert ((v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)) >= pow2 (pbits * (k - 1))) val bn_eval_update_sub: #t:limb_t -> len1:size_nat -> b1:lbignum t len1 -> len2:size_nat{len1 <= len2} -> Lemma (let b2 = create len2 (uint #t 0) in bn_v b1 == bn_v (update_sub b2 0 len1 b1)) let bn_eval_update_sub #t len1 b1 len2 = let b2 = create len2 (uint #t 0) in let b2 = update_sub b2 0 len1 b1 in bn_eval_split_i b2 len1; assert (bn_v b2 == bn_v b1 + pow2 (bits t * len1) * bn_v (slice b2 len1 len2)); let b_zeroes = create (len2 - len1) (uint #t 0) in eq_intro b_zeroes (slice b2 len1 len2); bn_eval_zeroes #t (len2 - len1) (len2 - len1) val bn_update_sub_eval: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (bn_v (update_sub a i bLen b) == bn_v a - bn_v (sub a i bLen) * pow2 (bits t * i) + bn_v b * pow2 (bits t * i)) let bn_update_sub_eval #t #aLen #bLen a b i = let pbits = bits t in let a' = update_sub a i bLen b in let c = bn_v (sub a i bLen) * pow2 (bits t * i) in calc (==) { bn_v a' + c; (==) { bn_eval_split_i a' i } bn_v (slice a' 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { eq_intro (slice a 0 i) (slice a' 0 i) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { bn_eval_split_i (slice a' i aLen) bLen } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a' (i + bLen) aLen)) + c; (==) { eq_intro (slice a' (i + bLen) aLen) (slice a (i + bLen) aLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) {eq_intro (sub a' i bLen) b } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v b + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * i)) (bn_v b) (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * i) * (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.paren_mul_right (pow2 (pbits * i)) (pow2 (pbits * bLen)) (bn_v (slice a (i + bLen) aLen)); Math.Lemmas.pow2_plus (pbits * i) (pbits * bLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen) + c; (==) { bn_eval_split_i (slice a 0 (i + bLen)) i } bn_v (slice a 0 (i + bLen)) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen); (==) { bn_eval_split_i a (i + bLen) } bn_v a + pow2 (pbits * i) * bn_v b; } val bn_upd_eval: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i < aLen} -> Lemma (bn_v (upd a i b1) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i)) let bn_upd_eval #t #aLen a b1 i = let b = create 1 b1 in bn_update_sub_eval a b i; bn_eval1 (sub a i 1); bn_eval1 b; assert (bn_v (update_sub a i 1 b) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i)); eq_intro (update_sub a i 1 b) (upd a i b1) val bn_concat_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> Lemma (bn_v (concat a b) == bn_v a + pow2 (bits t * aLen) * bn_v b) let bn_concat_lemma #t #aLen #bLen a b = let pbits = bits t in let res = concat a b in calc (==) { bn_v res; (==) { bn_eval_split_i res aLen } bn_v (slice res 0 aLen) + pow2 (pbits * aLen) * bn_v (slice res aLen (aLen + bLen)); (==) { eq_intro (slice res 0 aLen) a } bn_v a + pow2 (pbits * aLen) * bn_v (slice res aLen (aLen + bLen)); (==) { eq_intro (slice res aLen (aLen + bLen)) b } bn_v a + pow2 (pbits * aLen) * bn_v b; } val bn_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> mask:limb t -> Lemma (requires v mask == v (ones t SEC) \/ v mask == 0) (ensures bn_v (map (logand mask) b) == (if v mask = 0 then 0 else bn_v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> mask: Hacl.Spec.Bignum.Definitions.limb t -> FStar.Pervasives.Lemma (requires Lib.IntTypes.v mask == Lib.IntTypes.v (Lib.IntTypes.ones t Lib.IntTypes.SEC) \/ Lib.IntTypes.v mask == 0) (ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.map (Lib.IntTypes.logand mask) b) == (match Lib.IntTypes.v mask = 0 with | true -> 0 | _ -> Hacl.Spec.Bignum.Definitions.bn_v b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims._assert", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_zeroes", "Lib.Sequence.eq_intro", "Lib.IntTypes.int_t", "Lib.Sequence.create", "Lib.IntTypes.uint", "Prims.bool", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.op_String_Access", "Prims.l_True", "Prims.squash", "Lib.Sequence.index", "Prims.Nil", "FStar.Pervasives.pattern", "Lib.IntTypes.logand_lemma", "Lib.Sequence.lseq", "Prims.l_Forall", "Prims.l_imp", "Lib.IntTypes.logand", "Lib.Sequence.map" ]
[]
false
false
true
false
false
let bn_mask_lemma #t #len b mask =
let res = map (logand mask) b in let lemma_aux (i: nat{i < len}) : Lemma (v res.[ i ] == (if v mask = 0 then 0 else v b.[ i ])) = logand_lemma mask b.[ i ] in Classical.forall_intro lemma_aux; if v mask = 0 then (eq_intro res (create len (uint #t 0)); bn_eval_zeroes #t len len; assert (bn_v res == 0)) else eq_intro res b
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_zeroes
val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0)
val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0)
let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 54, "start_col": 0, "start_line": 48 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Lib.IntTypes.size_nat -> i: Prims.nat{i <= len} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.eval_ len (Lib.Sequence.create len (Lib.IntTypes.uint 0)) i == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_eval0", "Prims.bool", "Hacl.Spec.Bignum.Definitions.bn_eval_zeroes", "Prims.op_Subtraction", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Lib.IntTypes.SEC", "Prims.l_Forall", "Prims.l_imp", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_eval_zeroes #t len i =
let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else (bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1))
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_update_sub
val bn_eval_update_sub: #t:limb_t -> len1:size_nat -> b1:lbignum t len1 -> len2:size_nat{len1 <= len2} -> Lemma (let b2 = create len2 (uint #t 0) in bn_v b1 == bn_v (update_sub b2 0 len1 b1))
val bn_eval_update_sub: #t:limb_t -> len1:size_nat -> b1:lbignum t len1 -> len2:size_nat{len1 <= len2} -> Lemma (let b2 = create len2 (uint #t 0) in bn_v b1 == bn_v (update_sub b2 0 len1 b1))
let bn_eval_update_sub #t len1 b1 len2 = let b2 = create len2 (uint #t 0) in let b2 = update_sub b2 0 len1 b1 in bn_eval_split_i b2 len1; assert (bn_v b2 == bn_v b1 + pow2 (bits t * len1) * bn_v (slice b2 len1 len2)); let b_zeroes = create (len2 - len1) (uint #t 0) in eq_intro b_zeroes (slice b2 len1 len2); bn_eval_zeroes #t (len2 - len1) (len2 - len1)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 255, "start_col": 0, "start_line": 248 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i)) let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t)) let bn_eval_index #t #len b i = let pbits = bits t in calc (==) { bn_v b / pow2 (pbits * i) % pow2 pbits; (==) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; (==) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; (==) { bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i)) } bn_v (slice b i len) % pow2 pbits; (==) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; (==) { bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0 } v b.[i] % pow2 pbits; (==) { Math.Lemmas.modulo_lemma (v b.[i]) (pow2 pbits) } v b.[i]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[i]) val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k) let bn_eval_lt #t len a b k = let pbits = bits t in calc (==) { eval_ len b k - eval_ len a k; (==) { bn_eval_unfold_i b k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a k; (==) { bn_eval_unfold_i a k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a (k - 1) - v a.[k - 1] * pow2 (pbits * (k - 1)); (==) { Math.Lemmas.distributivity_sub_left (v b.[k - 1]) (v a.[k - 1]) (pow2 (pbits * (k - 1))) } eval_ len b (k - 1) - eval_ len a (k - 1) + (v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)); }; bn_eval_bound a (k - 1); bn_eval_bound b (k - 1); assert (eval_ len b (k - 1) - eval_ len a (k - 1) > - pow2 (pbits * (k - 1))); assert ((v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)) >= pow2 (pbits * (k - 1))) val bn_eval_update_sub: #t:limb_t -> len1:size_nat -> b1:lbignum t len1 -> len2:size_nat{len1 <= len2} -> Lemma (let b2 = create len2 (uint #t 0) in bn_v b1 == bn_v (update_sub b2 0 len1 b1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len1: Lib.IntTypes.size_nat -> b1: Hacl.Spec.Bignum.Definitions.lbignum t len1 -> len2: Lib.IntTypes.size_nat{len1 <= len2} -> FStar.Pervasives.Lemma (ensures (let b2 = Lib.Sequence.create len2 (Lib.IntTypes.uint 0) in Hacl.Spec.Bignum.Definitions.bn_v b1 == Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.update_sub b2 0 len1 b1)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Spec.Bignum.Definitions.bn_eval_zeroes", "Prims.op_Subtraction", "Prims.unit", "Lib.Sequence.eq_intro", "Hacl.Spec.Bignum.Definitions.limb", "Lib.Sequence.slice", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Lib.IntTypes.SEC", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint", "Prims._assert", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Lib.Sequence.sub", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.update_sub" ]
[]
true
false
true
false
false
let bn_eval_update_sub #t len1 b1 len2 =
let b2 = create len2 (uint #t 0) in let b2 = update_sub b2 0 len1 b1 in bn_eval_split_i b2 len1; assert (bn_v b2 == bn_v b1 + pow2 (bits t * len1) * bn_v (slice b2 len1 len2)); let b_zeroes = create (len2 - len1) (uint #t 0) in eq_intro b_zeroes (slice b2 len1 len2); bn_eval_zeroes #t (len2 - len1) (len2 - len1)
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_upd_eval
val bn_upd_eval: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i < aLen} -> Lemma (bn_v (upd a i b1) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i))
val bn_upd_eval: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i < aLen} -> Lemma (bn_v (upd a i b1) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i))
let bn_upd_eval #t #aLen a b1 i = let b = create 1 b1 in bn_update_sub_eval a b i; bn_eval1 (sub a i 1); bn_eval1 b; assert (bn_v (update_sub a i 1 b) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i)); eq_intro (update_sub a i 1 b) (upd a i b1)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 310, "start_col": 0, "start_line": 304 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i)) let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t)) let bn_eval_index #t #len b i = let pbits = bits t in calc (==) { bn_v b / pow2 (pbits * i) % pow2 pbits; (==) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; (==) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; (==) { bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i)) } bn_v (slice b i len) % pow2 pbits; (==) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; (==) { bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0 } v b.[i] % pow2 pbits; (==) { Math.Lemmas.modulo_lemma (v b.[i]) (pow2 pbits) } v b.[i]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[i]) val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k) let bn_eval_lt #t len a b k = let pbits = bits t in calc (==) { eval_ len b k - eval_ len a k; (==) { bn_eval_unfold_i b k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a k; (==) { bn_eval_unfold_i a k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a (k - 1) - v a.[k - 1] * pow2 (pbits * (k - 1)); (==) { Math.Lemmas.distributivity_sub_left (v b.[k - 1]) (v a.[k - 1]) (pow2 (pbits * (k - 1))) } eval_ len b (k - 1) - eval_ len a (k - 1) + (v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)); }; bn_eval_bound a (k - 1); bn_eval_bound b (k - 1); assert (eval_ len b (k - 1) - eval_ len a (k - 1) > - pow2 (pbits * (k - 1))); assert ((v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)) >= pow2 (pbits * (k - 1))) val bn_eval_update_sub: #t:limb_t -> len1:size_nat -> b1:lbignum t len1 -> len2:size_nat{len1 <= len2} -> Lemma (let b2 = create len2 (uint #t 0) in bn_v b1 == bn_v (update_sub b2 0 len1 b1)) let bn_eval_update_sub #t len1 b1 len2 = let b2 = create len2 (uint #t 0) in let b2 = update_sub b2 0 len1 b1 in bn_eval_split_i b2 len1; assert (bn_v b2 == bn_v b1 + pow2 (bits t * len1) * bn_v (slice b2 len1 len2)); let b_zeroes = create (len2 - len1) (uint #t 0) in eq_intro b_zeroes (slice b2 len1 len2); bn_eval_zeroes #t (len2 - len1) (len2 - len1) val bn_update_sub_eval: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (bn_v (update_sub a i bLen b) == bn_v a - bn_v (sub a i bLen) * pow2 (bits t * i) + bn_v b * pow2 (bits t * i)) let bn_update_sub_eval #t #aLen #bLen a b i = let pbits = bits t in let a' = update_sub a i bLen b in let c = bn_v (sub a i bLen) * pow2 (bits t * i) in calc (==) { bn_v a' + c; (==) { bn_eval_split_i a' i } bn_v (slice a' 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { eq_intro (slice a 0 i) (slice a' 0 i) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { bn_eval_split_i (slice a' i aLen) bLen } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a' (i + bLen) aLen)) + c; (==) { eq_intro (slice a' (i + bLen) aLen) (slice a (i + bLen) aLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) {eq_intro (sub a' i bLen) b } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v b + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * i)) (bn_v b) (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * i) * (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.paren_mul_right (pow2 (pbits * i)) (pow2 (pbits * bLen)) (bn_v (slice a (i + bLen) aLen)); Math.Lemmas.pow2_plus (pbits * i) (pbits * bLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen) + c; (==) { bn_eval_split_i (slice a 0 (i + bLen)) i } bn_v (slice a 0 (i + bLen)) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen); (==) { bn_eval_split_i a (i + bLen) } bn_v a + pow2 (pbits * i) * bn_v b; } val bn_upd_eval: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i < aLen} -> Lemma (bn_v (upd a i b1) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i < aLen} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.upd a i b1) == Hacl.Spec.Bignum.Definitions.bn_v a - Lib.IntTypes.v a.[ i ] * Prims.pow2 (Lib.IntTypes.bits t * i) + Lib.IntTypes.v b1 * Prims.pow2 (Lib.IntTypes.bits t * i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.eq_intro", "Lib.Sequence.update_sub", "Lib.Sequence.upd", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Addition", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Prims.pow2", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_eval1", "Lib.Sequence.sub", "Hacl.Spec.Bignum.Definitions.bn_update_sub_eval", "Lib.Sequence.lseq", "Prims.l_and", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Prims.l_Forall", "Prims.l_imp", "Lib.Sequence.index", "Lib.Sequence.create" ]
[]
true
false
true
false
false
let bn_upd_eval #t #aLen a b1 i =
let b = create 1 b1 in bn_update_sub_eval a b i; bn_eval1 (sub a i 1); bn_eval1 b; assert (bn_v (update_sub a i 1 b) == bn_v a - v a.[ i ] * pow2 (bits t * i) + v b1 * pow2 (bits t * i)); eq_intro (update_sub a i 1 b) (upd a i b1)
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_lt
val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k)
val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k)
let bn_eval_lt #t len a b k = let pbits = bits t in calc (==) { eval_ len b k - eval_ len a k; (==) { bn_eval_unfold_i b k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a k; (==) { bn_eval_unfold_i a k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a (k - 1) - v a.[k - 1] * pow2 (pbits * (k - 1)); (==) { Math.Lemmas.distributivity_sub_left (v b.[k - 1]) (v a.[k - 1]) (pow2 (pbits * (k - 1))) } eval_ len b (k - 1) - eval_ len a (k - 1) + (v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)); }; bn_eval_bound a (k - 1); bn_eval_bound b (k - 1); assert (eval_ len b (k - 1) - eval_ len a (k - 1) > - pow2 (pbits * (k - 1))); assert ((v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)) >= pow2 (pbits * (k - 1)))
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 242, "start_col": 0, "start_line": 227 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i)) let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t)) let bn_eval_index #t #len b i = let pbits = bits t in calc (==) { bn_v b / pow2 (pbits * i) % pow2 pbits; (==) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; (==) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; (==) { bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i)) } bn_v (slice b i len) % pow2 pbits; (==) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; (==) { bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0 } v b.[i] % pow2 pbits; (==) { Math.Lemmas.modulo_lemma (v b.[i]) (pow2 pbits) } v b.[i]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[i]) val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Lib.IntTypes.size_nat -> a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len -> k: Prims.pos{k <= len} -> FStar.Pervasives.Lemma (requires Lib.IntTypes.v a.[ k - 1 ] < Lib.IntTypes.v b.[ k - 1 ]) (ensures Hacl.Spec.Bignum.Definitions.eval_ len a k < Hacl.Spec.Bignum.Definitions.eval_ len b k)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims._assert", "Prims.op_GreaterThanOrEqual", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.pow2", "Prims.unit", "Prims.op_GreaterThan", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.op_Minus", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Prims.squash", "FStar.Math.Lemmas.distributivity_sub_left", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_eval_lt #t len a b k =
let pbits = bits t in calc ( == ) { eval_ len b k - eval_ len a k; ( == ) { bn_eval_unfold_i b k } eval_ len b (k - 1) + v b.[ k - 1 ] * pow2 (pbits * (k - 1)) - eval_ len a k; ( == ) { bn_eval_unfold_i a k } eval_ len b (k - 1) + v b.[ k - 1 ] * pow2 (pbits * (k - 1)) - eval_ len a (k - 1) - v a.[ k - 1 ] * pow2 (pbits * (k - 1)); ( == ) { Math.Lemmas.distributivity_sub_left (v b.[ k - 1 ]) (v a.[ k - 1 ]) (pow2 (pbits * (k - 1))) } eval_ len b (k - 1) - eval_ len a (k - 1) + (v b.[ k - 1 ] - v a.[ k - 1 ]) * pow2 (pbits * (k - 1)); }; bn_eval_bound a (k - 1); bn_eval_bound b (k - 1); assert (eval_ len b (k - 1) - eval_ len a (k - 1) > - pow2 (pbits * (k - 1))); assert ((v b.[ k - 1 ] - v a.[ k - 1 ]) * pow2 (pbits * (k - 1)) >= pow2 (pbits * (k - 1)))
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_concat_lemma
val bn_concat_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> Lemma (bn_v (concat a b) == bn_v a + pow2 (bits t * aLen) * bn_v b)
val bn_concat_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> Lemma (bn_v (concat a b) == bn_v a + pow2 (bits t * aLen) * bn_v b)
let bn_concat_lemma #t #aLen #bLen a b = let pbits = bits t in let res = concat a b in calc (==) { bn_v res; (==) { bn_eval_split_i res aLen } bn_v (slice res 0 aLen) + pow2 (pbits * aLen) * bn_v (slice res aLen (aLen + bLen)); (==) { eq_intro (slice res 0 aLen) a } bn_v a + pow2 (pbits * aLen) * bn_v (slice res aLen (aLen + bLen)); (==) { eq_intro (slice res aLen (aLen + bLen)) b } bn_v a + pow2 (pbits * aLen) * bn_v b; }
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 332, "start_col": 0, "start_line": 321 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i)) let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t)) let bn_eval_index #t #len b i = let pbits = bits t in calc (==) { bn_v b / pow2 (pbits * i) % pow2 pbits; (==) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; (==) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; (==) { bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i)) } bn_v (slice b i len) % pow2 pbits; (==) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; (==) { bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0 } v b.[i] % pow2 pbits; (==) { Math.Lemmas.modulo_lemma (v b.[i]) (pow2 pbits) } v b.[i]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[i]) val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k) let bn_eval_lt #t len a b k = let pbits = bits t in calc (==) { eval_ len b k - eval_ len a k; (==) { bn_eval_unfold_i b k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a k; (==) { bn_eval_unfold_i a k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a (k - 1) - v a.[k - 1] * pow2 (pbits * (k - 1)); (==) { Math.Lemmas.distributivity_sub_left (v b.[k - 1]) (v a.[k - 1]) (pow2 (pbits * (k - 1))) } eval_ len b (k - 1) - eval_ len a (k - 1) + (v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)); }; bn_eval_bound a (k - 1); bn_eval_bound b (k - 1); assert (eval_ len b (k - 1) - eval_ len a (k - 1) > - pow2 (pbits * (k - 1))); assert ((v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)) >= pow2 (pbits * (k - 1))) val bn_eval_update_sub: #t:limb_t -> len1:size_nat -> b1:lbignum t len1 -> len2:size_nat{len1 <= len2} -> Lemma (let b2 = create len2 (uint #t 0) in bn_v b1 == bn_v (update_sub b2 0 len1 b1)) let bn_eval_update_sub #t len1 b1 len2 = let b2 = create len2 (uint #t 0) in let b2 = update_sub b2 0 len1 b1 in bn_eval_split_i b2 len1; assert (bn_v b2 == bn_v b1 + pow2 (bits t * len1) * bn_v (slice b2 len1 len2)); let b_zeroes = create (len2 - len1) (uint #t 0) in eq_intro b_zeroes (slice b2 len1 len2); bn_eval_zeroes #t (len2 - len1) (len2 - len1) val bn_update_sub_eval: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (bn_v (update_sub a i bLen b) == bn_v a - bn_v (sub a i bLen) * pow2 (bits t * i) + bn_v b * pow2 (bits t * i)) let bn_update_sub_eval #t #aLen #bLen a b i = let pbits = bits t in let a' = update_sub a i bLen b in let c = bn_v (sub a i bLen) * pow2 (bits t * i) in calc (==) { bn_v a' + c; (==) { bn_eval_split_i a' i } bn_v (slice a' 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { eq_intro (slice a 0 i) (slice a' 0 i) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { bn_eval_split_i (slice a' i aLen) bLen } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a' (i + bLen) aLen)) + c; (==) { eq_intro (slice a' (i + bLen) aLen) (slice a (i + bLen) aLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) {eq_intro (sub a' i bLen) b } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v b + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * i)) (bn_v b) (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * i) * (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.paren_mul_right (pow2 (pbits * i)) (pow2 (pbits * bLen)) (bn_v (slice a (i + bLen) aLen)); Math.Lemmas.pow2_plus (pbits * i) (pbits * bLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen) + c; (==) { bn_eval_split_i (slice a 0 (i + bLen)) i } bn_v (slice a 0 (i + bLen)) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen); (==) { bn_eval_split_i a (i + bLen) } bn_v a + pow2 (pbits * i) * bn_v b; } val bn_upd_eval: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i < aLen} -> Lemma (bn_v (upd a i b1) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i)) let bn_upd_eval #t #aLen a b1 i = let b = create 1 b1 in bn_update_sub_eval a b i; bn_eval1 (sub a i 1); bn_eval1 b; assert (bn_v (update_sub a i 1 b) == bn_v a - v a.[i] * pow2 (bits t * i) + v b1 * pow2 (bits t * i)); eq_intro (update_sub a i 1 b) (upd a i b1) val bn_concat_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> Lemma (bn_v (concat a b) == bn_v a + pow2 (bits t * aLen) * bn_v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.concat a b) == Hacl.Spec.Bignum.Definitions.bn_v a + Prims.pow2 (Lib.IntTypes.bits t * aLen) * Hacl.Spec.Bignum.Definitions.bn_v b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "FStar.Calc.calc_finish", "Prims.nat", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.squash", "Lib.Sequence.eq_intro", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.append", "Lib.Sequence.concat", "Prims.int", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_concat_lemma #t #aLen #bLen a b =
let pbits = bits t in let res = concat a b in calc ( == ) { bn_v res; ( == ) { bn_eval_split_i res aLen } bn_v (slice res 0 aLen) + pow2 (pbits * aLen) * bn_v (slice res aLen (aLen + bLen)); ( == ) { eq_intro (slice res 0 aLen) a } bn_v a + pow2 (pbits * aLen) * bn_v (slice res aLen (aLen + bLen)); ( == ) { eq_intro (slice res aLen (aLen + bLen)) b } bn_v a + pow2 (pbits * aLen) * bn_v b; }
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_bound
val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i))
val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i))
let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 193, "start_col": 0, "start_line": 174 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Prims.nat{i <= len} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.eval_ len b i < Prims.pow2 (Lib.IntTypes.bits t * i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_eval0", "Prims.bool", "Prims._assert", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.pow2", "FStar.Mul.op_Star", "Prims.unit", "FStar.Calc.calc_finish", "Prims.op_Addition", "Prims.op_Subtraction", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.Cons", "FStar.Preorder.relation", "Prims.eq2", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_right", "FStar.Math.Lemmas.lemma_mult_le_left", "FStar.Math.Lemmas.pow2_plus", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Lib.IntTypes.bits" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_eval_bound #t #len b i =
let pbits = bits t in if i = 0 then bn_eval0 b else (bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[ i - 1 ]); calc ( < ) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[ i - 1 ]; ( < ) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[ i - 1 ]; ( == ) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[ i - 1 ]) } pow2 (pbits * (i - 1)) * (1 + v b.[ i - 1 ]); ( <= ) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[ i - 1 ]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; ( == ) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)))
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j
val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j)
val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j)
let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 89, "start_col": 0, "start_line": 73 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
b1: Hacl.Spec.Bignum.Definitions.lbignum t len1 -> b2: Hacl.Spec.Bignum.Definitions.lbignum t len2 -> j: Prims.nat{j <= len1 /\ j <= len2} -> FStar.Pervasives.Lemma (requires Lib.Sequence.sub b1 0 j == Lib.Sequence.sub b2 0 j) (ensures Hacl.Spec.Bignum.Definitions.eval_ len1 b1 j == Hacl.Spec.Bignum.Definitions.eval_ len2 b2 j ) (decreases j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_eval0", "Prims.unit", "Prims.bool", "Prims._assert", "Prims.eq2", "Lib.IntTypes.range_t", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Subtraction", "FStar.Seq.Base.lemma_index_slice", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Lib.Sequence.eq_intro", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.l_Forall", "Prims.op_LessThan", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j =
if j = 0 then (bn_eval0 b1; bn_eval0 b2) else (bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[ j - 1 ] == v b2.[ j - 1 ]); ())
false
DoublyLinkedList.fst
DoublyLinkedList.tot_dll_to_fragment_split
val tot_dll_to_fragment_split (#t: Type) (h0: heap) (d: dll t {dll_valid h0 d}) (n1 n2: pointer (node t)) : Pure (fragment t) (requires (n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1 @ h0 |>> n2 /\ n1 <<| n2 @ h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == (reveal p1.pnodes) `append` (reveal p2.pnodes))))
val tot_dll_to_fragment_split (#t: Type) (h0: heap) (d: dll t {dll_valid h0 d}) (n1 n2: pointer (node t)) : Pure (fragment t) (requires (n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1 @ h0 |>> n2 /\ n1 <<| n2 @ h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == (reveal p1.pnodes) `append` (reveal p2.pnodes))))
let tot_dll_to_fragment_split (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d}) (n1 n2:pointer (node t)) : Pure (fragment t) (requires ( n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1@h0 |>> n2 /\ n1 <<| n2@h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == reveal p1.pnodes `append` reveal p2.pnodes))) = let split_nodes = elift2_p split_using d.nodes (hide n2) in lemma_split_using d.nodes n2; let l1 = elift1 fst split_nodes in let l2 = elift1 snd split_nodes in let p1 = { phead = d.lhead ; ptail = n1 ; pnodes = l1 } in let p2 = { phead = n2 ; ptail = d.ltail ; pnodes = l2 } in let f = Frag2 p1 p2 in dll_fp0_is_nodelist_fp0 d; // assert (loc_equiv (dll_fp0 d) (nodelist_fp0 (reveal d.nodes))); nodelist_split_fp0_equiv l1 l2; nodelist_split_valid h0 l1 l2; lemma_unsnoc_is_last l1; lemma_unsnoc_is_last l2; lemma_unsnoc_is_last (reveal d.nodes); // assert (piece_ghostly_connections p1); // assert ( n2 == hd (reveal l2) ); lemma_append_last l1 l2; // assert ( last (reveal l2) == last (append (reveal l1) (reveal l2)) ); // assert ( d.ltail == last (reveal l2) ); // assert (piece_ghostly_connections p2); // assert (fragment_ghostly_connections f); // assert (nodelist_contained h0 (reveal p1.pnodes)); // assert (nodelist_contained h0 (reveal p2.pnodes)); extract_nodelist_contained h0 l1 (length l1 - 1); // assert (h0 `contains` p1.ptail); // assert (fragment_contained h0 f); // assert (nodelist_aa (reveal p1.pnodes)); // assert (nodelist_aa (reveal p2.pnodes)); piece_fp0_is_nodelist_fp0 p1; piece_fp0_is_nodelist_fp0 p2; // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2)))); // assert (loc_equiv (nodelist_fp0 (reveal l1)) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 (reveal l2)) (piece_fp0 p2)); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2))) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); loc_equiv_trans (dll_fp0 d) (Mod.loc_union (nodelist_fp0 l1) (nodelist_fp0 l2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // assert (Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)); // assert (fragment_aa f); // assert (nodelist_conn h0 (reveal p1.pnodes)); // assert (nodelist_conn h0 (reveal p2.pnodes)); // assert (fragment_conn h0 f); f
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 1150, "start_col": 0, "start_line": 1089 }
(* Copyright 2008-2019 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 DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl let dll_valid (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d let piece_valid (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = piece_ghostly_connections p /\ piece_contained h0 p /\ piece_aa p /\ piece_conn h0 p let fragment_valid (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_ghostly_connections f /\ fragment_contained h0 f /\ fragment_aa f /\ fragment_conn h0 f /// Talk about payloads of nodes remaining constant let unchanged_node_val h0 h1 n = (h0 `contains` n ==> ((n@h0).p == (n@h1).p /\ h1 `contains` n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:nodelist 'a) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Useful operations on nodes let ( =|> ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ b@h0 == b@h1 /\ (a@h1) |>> b)) = a *= { !*a with flink = b } let ( <|= ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer b) h0 h1 /\ a@h0 == a@h1 /\ unchanged_node_val h0 h1 b /\ (b@h0).flink == (b@h1).flink /\ a <<| (b@h1))) = b *= { !*b with blink = a } let ( !=|> ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ (a@h1).flink == null)) = a *= { !*a with flink = null } let ( !<|= ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).flink == (a@h1).flink /\ (a@h1).blink == null)) = a *= { !*a with blink = null } /// Extraction lemmas: these allow one to use one of the properties /// above, which are defined inductively, to get the property at one /// of the latter elements of the list. let rec extract_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_contained h0 nl)) (ensures (h0 `contains` nl.[i])) = match i with | 0 -> () | _ -> extract_nodelist_contained h0 (tl nl) (i - 1) let rec extract_nodelist_fp0 (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer nl.[i]))) = match i with | 0 -> () | _ -> extract_nodelist_fp0 (tl nl) (i - 1) let rec extract_nodelist_aa_r (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_r nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 right))) = match i with | 0 -> () | _ -> extract_nodelist_aa_r (tl nl) (i - 1) let rec extract_nodelist_aa_l (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_l nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 left))) (decreases (length nl)) = if i = length nl - 1 then () else ( let a, b = unsnoc nl in lemma_unsnoc_length nl; let left, n, right = split3 nl i in lemma_unsnoc_split3 nl i; // assert (append (left) (n :: (fst (unsnoc right))) == a); extract_nodelist_aa_l a i; lemma_split3_unsnoc nl i ) let rec extract_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl - 1}) : Lemma (requires (nodelist_conn h0 nl)) (ensures ( (nl.[i]@h0 |>> nl.[i+1]) /\ (nl.[i] <<| nl.[i+1]@h0))) (decreases (length nl)) = match i with | 0 -> () | _ -> extract_nodelist_conn h0 (tl nl) (i - 1) /// Validity is maintained upon breaking the lists, via (hd :: tl) let rec nodelist_remains_aa_l (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa_l nl /\ length nl > 0)) (ensures (nodelist_aa_l (tl nl))) (decreases (length nl)) [SMTPat (nodelist_aa_l (tl nl))] = match nl with | [n] -> () | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; let ns', n' = unsnoc (tl nl) in // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (n' == n); // assert (ns' == tl ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns')); nodelist_remains_aa_l ns (* Rest of the validity predicates are held trivially due to their direction of definition *) /// Properties maintained upon breaking the list, via unsnoc let rec fst_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> fst_unsnoc_nodelist_fp0 ns let rec snd_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> snd_unsnoc_nodelist_fp0 ns let rec fst_unsnoc_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_contained h0 nl /\ length nl > 0)) (ensures (nodelist_contained h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_contained h0 (tl nl) let rec fst_unsnoc_nodelist_aa (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa nl /\ length nl > 0)) (ensures (nodelist_aa (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_aa (tl nl); // assert (nodelist_aa_l (fst (unsnoc nl))); let n :: ns = fst (unsnoc nl) in Mod.loc_disjoint_includes (Mod.loc_buffer n) (nodelist_fp0 (tl nl)) (Mod.loc_buffer n) (nodelist_fp0 ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (nodelist_aa_r (fst (unsnoc nl))); () let rec fst_unsnoc_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_conn h0 nl /\ length nl > 0)) (ensures (nodelist_conn h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_conn h0 (tl nl) let fst_unsnoc_nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_valid h0 nl /\ length nl > 0)) (ensures (nodelist_valid h0 (fst (unsnoc nl)))) = fst_unsnoc_nodelist_contained h0 nl; fst_unsnoc_nodelist_aa nl; fst_unsnoc_nodelist_conn h0 nl /// Footprints are included, even upon breaking nodelist even further let rec nodelist_includes_r_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let _, a = splitAt i nl in let _, b = splitAt j nl in Mod.loc_includes (nodelist_fp0 a) (nodelist_fp0 b))) (decreases (j - i)) = if i = j then () else ( let temp, a = splitAt i nl in lemma_splitAt nl temp a i; let temp, b = splitAt j nl in lemma_splitAt nl temp b j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (tl a == b); () ) else ( nodelist_includes_r_fp0 nl i (j - 1); nodelist_includes_r_fp0 nl (j - 1) j; let temp, c = splitAt (j - 1) nl in lemma_splitAt nl temp c (j - 1); Mod.loc_includes_trans (nodelist_fp0 a) (nodelist_fp0 c) (nodelist_fp0 b) ) ) let rec nodelist_includes_l_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let a, _ = splitAt i nl in let b, _ = splitAt j nl in Mod.loc_includes (nodelist_fp0 b) (nodelist_fp0 a))) (decreases (j - i)) = if i = j then () else ( let a, a' = splitAt i nl in lemma_splitAt nl a a' i; let b, b' = splitAt j nl in lemma_splitAt nl b b' j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (b == append a [hd a']); lemma_unsnoc_append a [hd a']; // assert (snd (unsnoc b) == hd a'); // assert (fst (unsnoc b) == a); fst_unsnoc_nodelist_fp0 b ) else ( nodelist_includes_l_fp0 nl i (j - 1); nodelist_includes_l_fp0 nl (j - 1) j; let c, c' = splitAt (j - 1) nl in lemma_splitAt nl c c' (j - 1); Mod.loc_includes_trans (nodelist_fp0 b) (nodelist_fp0 c) (nodelist_fp0 a) ) ) /// Total conversions between fragments, pieces, and dlls let tot_dll_to_piece (#t:Type) (h0:heap) (d:nonempty_dll t{dll_valid h0 d}) : Tot (p:piece t{piece_valid h0 p}) = { phead = d.lhead ; ptail = d.ltail ; pnodes = d.nodes } let tot_dll_to_fragment (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d /\ d.lhead =!= null}) : Tot (f:fragment t{fragment_valid h0 f}) = Frag1 (tot_dll_to_piece h0 d) let tot_piece_to_dll (#t:Type) (h0:heap) (p:piece t{ piece_valid h0 p /\ (p.phead@h0).blink == null /\ (p.ptail@h0).flink == null}) : Tot (d:dll t{dll_valid h0 d}) = { lhead = p.phead ; ltail = p.ptail ; nodes = p.pnodes } (* The conversions piece<->fragment are trivial *) /// Properties maintained when appending nodelists let rec nodelist_append_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) (ensures (nodelist_contained h0 (append nl1 nl2))) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_append_contained h0 nl1' nl2 let rec nodelist_append_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ( loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)))) = match nl1 with | [] -> () | n :: nl1' -> nodelist_append_fp0 nl1' nl2; // assert (loc_equiv // (nodelist_fp0 (append nl1' nl2)) // (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))); // assert (loc_equiv // (nodelist_fp0 nl1) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1'))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1')) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); loc_equiv_trans (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); () #set-options "--z3rlimit 20" let rec nodelist_append_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l nl1 /\ nodelist_aa_l nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_l (append nl1 nl2))) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; nodelist_append_fp0 nl1 nl2'; // assert (nodelist_aa_l nl2'); assert (Mod.loc_includes (nodelist_fp0 nl2) (nodelist_fp0 nl2')); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); lemma_unsnoc_is_last nl2; assert (Mod.loc_includes (nodelist_fp0 nl2) (Mod.loc_buffer n)); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl1)); // assert (loc_equiv (nodelist_fp0 (append nl1 nl2')) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2'))); nodelist_append_aa_l nl1 nl2'; // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (append nl1 nl2'))); lemma_unsnoc_append nl1 nl2; // assert (append nl1 nl2' == fst (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (fst (unsnoc (append nl1 nl2))))); () #reset-options let rec nodelist_append_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r nl1 /\ nodelist_aa_r nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_r (append nl1 nl2))) = match nl1 with | [] -> () | _ -> nodelist_append_fp0 (tl nl1) nl2; nodelist_append_aa_r (tl nl1) nl2 let nodelist_append_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa (append nl1 nl2))) = nodelist_append_aa_l nl1 nl2; nodelist_append_aa_r nl1 nl2 let rec nodelist_append_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_conn h0 (append nl1 nl2))) = match nl1 with | [_] -> () | _ -> nodelist_append_conn h0 (tl nl1) nl2 let nodelist_append_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_valid h0 (append nl1 nl2))) = nodelist_append_contained h0 nl1 nl2; nodelist_append_aa nl1 nl2; nodelist_append_conn h0 nl1 nl2 /// Useful property for for piece merging let loc_includes_union_r_inv (a b c:Mod.loc) : Lemma (requires (Mod.loc_includes a (Mod.loc_union b c))) (ensures (Mod.loc_includes a b /\ Mod.loc_includes a c)) = Mod.loc_includes_union_l b c b; Mod.loc_includes_trans a (Mod.loc_union b c) b; Mod.loc_includes_union_l b c c; Mod.loc_includes_trans a (Mod.loc_union b c) c /// Piece merging #set-options "--z3rlimit 10" val piece_merge (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Pure (piece t) (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (fun p -> (piece_valid h0 p) /\ (reveal p.pnodes == p1.pnodes `append` p2.pnodes))) let piece_merge #t h0 p1 p2 = let p = { phead = p1.phead ; ptail = p2.ptail ; pnodes = p1.pnodes ^@^ p2.pnodes } in lemma_append_last p1.pnodes p2.pnodes; nodelist_append_valid h0 p1.pnodes p2.pnodes; p #reset-options let piece_merge_fp0 (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Lemma (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (loc_equiv (piece_fp0 (piece_merge h0 p1 p2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)))) = let p = piece_merge h0 p1 p2 in let n1, n2, n = reveal p1.pnodes, reveal p2.pnodes, reveal p.pnodes in nodelist_append_fp0 n1 n2; // assert (loc_equiv (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); // assert (hd n1 == p1.phead); // assert (Mod.loc_includes (nodelist_fp0 n1) (Mod.loc_buffer p1.phead)); // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.phead)); // assert (last n2 == p2.ptail); extract_nodelist_fp0 n2 (length n2 - 1); lemma_unsnoc_is_last n2; // assert (Mod.loc_includes (nodelist_fp0 n2) (Mod.loc_buffer p2.ptail)); extract_nodelist_fp0 n (length n - 1); lemma_unsnoc_is_last n; // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.ptail)); loc_includes_union_r_inv (nodelist_fp0 n) (nodelist_fp0 n1) (nodelist_fp0 n2); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n1)); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n2)); // // assert (loc_equiv (nodelist_fp0 n) (piece_fp0 p)); extract_nodelist_fp0 n1 (length n1 - 1); lemma_unsnoc_is_last n1; // assert (loc_equiv (nodelist_fp0 n1) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 n2) (piece_fp0 p2)); // // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); Mod.loc_includes_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); Mod.loc_includes_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (Mod.loc_includes (piece_fp0 p) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // // assert (Mod.loc_includes (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (nodelist_fp0 n)); loc_equiv_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); loc_equiv_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); loc_equiv_trans (piece_fp0 p) (nodelist_fp0 n) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)) /// Fragment merging to a dll let rec fragment_defragmentable (#t:Type) (h0:heap) (f:fragment t{fragment_valid h0 f}) : GTot Type0 = let aux (p1 p2:(p:piece t{piece_valid h0 p})) = let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\(a <<| b@h0) in match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> aux p1 p2 | Frag3 p1 p2 p3 -> aux p1 p2 /\ aux p2 p3 let single_piece_fragment_valid (#t:Type) (h0:heap) (p:piece t) : Lemma (requires (piece_valid h0 p)) (ensures (fragment_valid h0 (Frag1 p))) = () #set-options "--z3rlimit 40 --initial_ifuel 2" let tot_defragmentable_fragment_to_dll (#t:Type) (h0:heap) (f:fragment t{ fragment_valid h0 f /\ fragment_defragmentable h0 f /\ (fragment_length f > 0 ==> (let a, b = match f with | Frag1 p1 -> p1, p1 | Frag2 p1 p2 -> p1, p2 | Frag3 p1 _ p3 -> p1, p3 in ((a.phead@h0).blink == null) /\ ((b.ptail@h0).flink == null))) }) : Tot (d:dll t{dll_valid h0 d /\ dll_fp0 d `loc_equiv` fragment_fp0 f /\ (reveal d.nodes == ( match f with | Frag0 -> [] | Frag1 p1 -> reveal p1.pnodes | Frag2 p1 p2 -> reveal p1.pnodes `append` reveal p2.pnodes | Frag3 p1 p2 p3 -> reveal p1.pnodes `append` reveal p2.pnodes `append` reveal p3.pnodes)) }) = match f with | Frag0 -> empty_list | Frag1 p1 -> tot_piece_to_dll h0 p1 | Frag2 p1 p2 -> piece_merge_fp0 h0 p1 p2; tot_piece_to_dll h0 (piece_merge h0 p1 p2) | Frag3 p1 p2 p3 -> piece_merge_fp0 h0 p1 p2; let p' = piece_merge h0 p1 p2 in piece_merge_fp0 h0 p' p3; tot_piece_to_dll h0 (piece_merge h0 p' p3) #reset-options /// Properties of nodelists maintained upon splitting nodelists let rec nodelist_split_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 (append nl1 nl2))) (ensures (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_split_contained h0 nl1' nl2 let rec nodelist_split_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = match nl1 with | [] | [_] -> () | _ -> match nl2 with | [] -> () | _ -> // assert (length nl1 > 1); // assert (length nl2 > 0); nodelist_split_fp0 (tl nl1) nl2; append_length nl1 nl2; nodelist_includes_r_fp0 (tl (append nl1 nl2)) 0 (length nl1 - 1); // assert (snd (splitAt 0 (tl (append nl1 nl2))) == tl (append nl1 nl2)); // assert (snd (splitAt (length nl1 - 1) (tl (append nl1 nl2))) == snd (splitAt (length nl1) (append nl1 nl2))); lemma_append_splitAt nl1 nl2; // assert (snd (splitAt (length nl1) (append nl1 nl2)) == nl2); // assert (Mod.loc_includes (nodelist_fp0 (tl (append nl1 nl2))) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl (append nl1 nl2)))); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (nodelist_fp0 (tl nl1)) (nodelist_fp0 nl2)); Mod.loc_disjoint_union_r (nodelist_fp0 nl2) (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1)); // assert (Mod.loc_disjoint (Mod.loc_union (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1))) (nodelist_fp0 nl2)); () #set-options "--z3rlimit 30" let rec nodelist_split_fp0_equiv (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ((loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2))))) = match nl1 with | [] -> () | n :: ns -> nodelist_split_fp0_equiv ns nl2; assert (loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2)))); // OBSERVE assert (loc_equiv (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns)) (nodelist_fp0 nl2))) // OBSERVE let rec nodelist_split_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l (append nl1 nl2))) (ensures (nodelist_aa_l nl1 /\ nodelist_aa_l nl2)) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; lemma_unsnoc_append nl1 nl2; // assert (nodelist_aa_l (append nl1 nl2)); // assert (nodelist_aa_l (append nl1 nl2')); nodelist_split_aa_l nl1 nl2'; // assert (nodelist_aa_l nl2'); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc nl2)); nodelist_append_fp0 nl1 nl2'; // assert (Mod.loc_includes (nodelist_fp0 (append nl1 nl2')) (nodelist_fp0 nl2')); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); // assert (nodelist_aa_l nl2); () #reset-options let rec nodelist_split_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (nodelist_aa_r nl1 /\ nodelist_aa_r nl2)) = match nl1 with | [] -> () | _ -> nodelist_split_aa_r (tl nl1) nl2; nodelist_append_fp0 (tl nl1) nl2 let nodelist_split_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa (append nl1 nl2))) (ensures (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = nodelist_split_fp0 nl1 nl2; nodelist_split_aa_l nl1 nl2; nodelist_split_aa_r nl1 nl2 let rec nodelist_split_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires ( (nodelist_conn h0 (append nl1 nl2)) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = match nl1 with | [_] -> () | _ -> nodelist_split_conn h0 (tl nl1) nl2 let nodelist_split_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 (append nl1 nl2) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = nodelist_split_contained h0 nl1 nl2; nodelist_split_aa nl1 nl2; nodelist_split_conn h0 nl1 nl2 /// Useful lemma to convert from dll_fp0 or piece_fp0 to nodelist_fp0 /// and vice-versa let dll_fp0_is_nodelist_fp0 (#t:Type) (d:dll t) : Lemma (requires (dll_ghostly_connections d)) (ensures (loc_equiv (dll_fp0 d) (nodelist_fp0 d.nodes))) = if length d.nodes > 0 then lemma_unsnoc_is_last d.nodes else () let piece_fp0_is_nodelist_fp0 (#t:Type) (p:piece t) : Lemma (requires (piece_ghostly_connections p)) (ensures (loc_equiv (piece_fp0 p) (nodelist_fp0 p.pnodes))) = lemma_unsnoc_is_last (reveal p.pnodes) /// Tot dll to fragment, with splitting #set-options "--z3rlimit 60 --initial_fuel 8 --initial_ifuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "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": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 8, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> d: DoublyLinkedList.dll t {DoublyLinkedList.dll_valid h0 d} -> n1: LowStar.Buffer.pointer (DoublyLinkedList.node t) -> n2: LowStar.Buffer.pointer (DoublyLinkedList.node t) -> Prims.Pure (DoublyLinkedList.fragment t)
Prims.Pure
[]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.dll", "DoublyLinkedList.dll_valid", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "Prims.unit", "DoublyLinkedList.loc_equiv_trans", "DoublyLinkedList.dll_fp0", "LowStar.Monotonic.Buffer.loc_union", "DoublyLinkedList.nodelist_fp0", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.piece_fp0", "DoublyLinkedList.piece_fp0_is_nodelist_fp0", "DoublyLinkedList.extract_nodelist_contained", "Prims.op_Subtraction", "FStar.List.Tot.Base.length", "FStar.List.Tot.Properties.lemma_append_last", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedList.__proj__Mkdll__item__nodes", "DoublyLinkedList.nodelist_split_valid", "DoublyLinkedList.nodelist_split_fp0_equiv", "DoublyLinkedList.dll_fp0_is_nodelist_fp0", "DoublyLinkedList.fragment", "DoublyLinkedList.Frag2", "DoublyLinkedList.piece", "DoublyLinkedList.Mkpiece", "DoublyLinkedList.__proj__Mkdll__item__ltail", "DoublyLinkedList.__proj__Mkdll__item__lhead", "FStar.Ghost.erased", "Prims.eq2", "FStar.Pervasives.Native.snd", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Ghost.elift1", "FStar.Pervasives.Native.fst", "FStar.List.Tot.Properties.lemma_split_using", "FStar.List.Tot.Properties.split_using", "FStar.Ghost.hide", "FStar.Ghost.elift2_p", "FStar.List.Tot.Base.memP", "Prims.l_and", "DoublyLinkedList.op_Bar_Greater_Greater", "DoublyLinkedList.op_At", "DoublyLinkedList.op_Less_Less_Bar", "DoublyLinkedList.fragment_valid", "Prims.b2t", "Prims.op_Equality", "Prims.int", "DoublyLinkedList.fragment_length", "DoublyLinkedList.loc_equiv", "DoublyLinkedList.fragment_fp0", "FStar.List.Tot.Base.append", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "Prims.logical", "LowStar.Monotonic.Buffer.get", "LowStar.Buffer.trivial_preorder" ]
[]
false
false
false
false
false
let tot_dll_to_fragment_split (#t: Type) (h0: heap) (d: dll t {dll_valid h0 d}) (n1 n2: pointer (node t)) : Pure (fragment t) (requires (n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1 @ h0 |>> n2 /\ n1 <<| n2 @ h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == (reveal p1.pnodes) `append` (reveal p2.pnodes)))) =
let split_nodes = elift2_p split_using d.nodes (hide n2) in lemma_split_using d.nodes n2; let l1 = elift1 fst split_nodes in let l2 = elift1 snd split_nodes in let p1 = { phead = d.lhead; ptail = n1; pnodes = l1 } in let p2 = { phead = n2; ptail = d.ltail; pnodes = l2 } in let f = Frag2 p1 p2 in dll_fp0_is_nodelist_fp0 d; nodelist_split_fp0_equiv l1 l2; nodelist_split_valid h0 l1 l2; lemma_unsnoc_is_last l1; lemma_unsnoc_is_last l2; lemma_unsnoc_is_last (reveal d.nodes); lemma_append_last l1 l2; extract_nodelist_contained h0 l1 (length l1 - 1); piece_fp0_is_nodelist_fp0 p1; piece_fp0_is_nodelist_fp0 p2; loc_equiv_trans (dll_fp0 d) (Mod.loc_union (nodelist_fp0 l1) (nodelist_fp0 l2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); f
false
Hacl.Test.ECDSA.fst
Hacl.Test.ECDSA.siggen_vectors256_tmp
val siggen_vectors256_tmp : Prims.list ((((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded)
let siggen_vectors256_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_256
{ "file_name": "code/tests/Hacl.Test.ECDSA.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 36, "start_col": 0, "start_line": 34 }
module Hacl.Test.ECDSA open FStar.HyperStack.ST open Test.Lowstarize open Lib.IntTypes open Hacl.P256 open Spec.ECDSA.Test.Vectors module L = Test.Lowstarize module B = LowStar.Buffer #set-options "--fuel 0 --ifuel 0 --z3rlimit 100" noextract let sigver_vectors256_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256 noextract let sigver_vectors384_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_384 noextract let sigver_vectors512_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_512
{ "checked_file": "/", "dependencies": [ "Test.Lowstarize.fst.checked", "Spec.P256.fst.checked", "Spec.ECDSA.Test.Vectors.fst.checked", "prims.fst.checked", "LowStar.Printf.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.P256.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.ECDSA.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": false, "full_module": "Spec.ECDSA.Test.Vectors", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list ((((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded)
Prims.Tot
[ "total" ]
[]
[ "FStar.List.Tot.Base.map", "Spec.ECDSA.Test.Vectors.vec_SigGen", "FStar.Pervasives.Native.tuple7", "Test.Lowstarize.hex_encoded", "FStar.Pervasives.Native.Mktuple7", "Test.Lowstarize.h", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__msg'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__d", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__qx'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__qy'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__k", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__r'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__s'", "Spec.ECDSA.Test.Vectors.siggen_vectors_sha2_256" ]
[]
false
false
false
true
false
let siggen_vectors256_tmp =
List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_256
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_split_i
val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i))
val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i))
let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 151, "start_col": 0, "start_line": 127 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Prims.nat{i <= len} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v b == Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.slice b 0 i) + Prims.pow2 (Lib.IntTypes.bits t * i) * Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.slice b i len)) (decreases len - i)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_eval0", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "Prims.bool", "Prims.l_or", "Lib.IntTypes.max_size_t", "Prims.unit", "FStar.Calc.calc_finish", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Addition", "Hacl.Spec.Bignum.Definitions.eval_", "FStar.Mul.op_Star", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.squash", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i_aux", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Prims._assert", "FStar.Seq.Base.lemma_index_slice", "Hacl.Spec.Bignum.Definitions.bn_eval1", "Lib.Sequence.lseq", "Prims.l_and", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.index", "Lib.IntTypes.bits" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_eval_split_i #t #len b i =
let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else if len = i then bn_eval0 (slice b i len) else let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[ 0 ] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[ i ] + pow2 pbits * bn_v (slice b (i + 1) len)); calc ( == ) { bn_v b; ( == ) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); ( == ) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[ i ]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[ i ]; ( == ) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1) } eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; ( == ) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; ()
false
Hacl.Test.ECDSA.fst
Hacl.Test.ECDSA.sigver_vectors512_tmp
val sigver_vectors512_tmp : Prims.list (((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Prims.bool)
let sigver_vectors512_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_512
{ "file_name": "code/tests/Hacl.Test.ECDSA.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 30, "start_col": 0, "start_line": 28 }
module Hacl.Test.ECDSA open FStar.HyperStack.ST open Test.Lowstarize open Lib.IntTypes open Hacl.P256 open Spec.ECDSA.Test.Vectors module L = Test.Lowstarize module B = LowStar.Buffer #set-options "--fuel 0 --ifuel 0 --z3rlimit 100" noextract let sigver_vectors256_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256 noextract let sigver_vectors384_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_384
{ "checked_file": "/", "dependencies": [ "Test.Lowstarize.fst.checked", "Spec.P256.fst.checked", "Spec.ECDSA.Test.Vectors.fst.checked", "prims.fst.checked", "LowStar.Printf.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.P256.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.ECDSA.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": false, "full_module": "Spec.ECDSA.Test.Vectors", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list (((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Prims.bool)
Prims.Tot
[ "total" ]
[]
[ "FStar.List.Tot.Base.map", "Spec.ECDSA.Test.Vectors.vec_SigVer", "FStar.Pervasives.Native.tuple6", "Test.Lowstarize.hex_encoded", "Prims.bool", "FStar.Pervasives.Native.Mktuple6", "Test.Lowstarize.h", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__msg", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__qx", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__qy", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__r", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__s", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__result", "Spec.ECDSA.Test.Vectors.sigver_vectors_sha2_512" ]
[]
false
false
false
true
false
let sigver_vectors512_tmp =
List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_512
false
Hacl.Test.ECDSA.fst
Hacl.Test.ECDSA.sigver_vectors384_tmp
val sigver_vectors384_tmp : Prims.list (((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Prims.bool)
let sigver_vectors384_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_384
{ "file_name": "code/tests/Hacl.Test.ECDSA.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 25, "start_col": 0, "start_line": 23 }
module Hacl.Test.ECDSA open FStar.HyperStack.ST open Test.Lowstarize open Lib.IntTypes open Hacl.P256 open Spec.ECDSA.Test.Vectors module L = Test.Lowstarize module B = LowStar.Buffer #set-options "--fuel 0 --ifuel 0 --z3rlimit 100" noextract let sigver_vectors256_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256
{ "checked_file": "/", "dependencies": [ "Test.Lowstarize.fst.checked", "Spec.P256.fst.checked", "Spec.ECDSA.Test.Vectors.fst.checked", "prims.fst.checked", "LowStar.Printf.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.P256.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.ECDSA.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": false, "full_module": "Spec.ECDSA.Test.Vectors", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list (((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Prims.bool)
Prims.Tot
[ "total" ]
[]
[ "FStar.List.Tot.Base.map", "Spec.ECDSA.Test.Vectors.vec_SigVer", "FStar.Pervasives.Native.tuple6", "Test.Lowstarize.hex_encoded", "Prims.bool", "FStar.Pervasives.Native.Mktuple6", "Test.Lowstarize.h", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__msg", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__qx", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__qy", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__r", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__s", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__result", "Spec.ECDSA.Test.Vectors.sigver_vectors_sha2_384" ]
[]
false
false
false
true
false
let sigver_vectors384_tmp =
List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_384
false
Hacl.Test.ECDSA.fst
Hacl.Test.ECDSA.siggen_vectors512_tmp
val siggen_vectors512_tmp : Prims.list ((((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded)
let siggen_vectors512_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_512
{ "file_name": "code/tests/Hacl.Test.ECDSA.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 46, "start_col": 0, "start_line": 44 }
module Hacl.Test.ECDSA open FStar.HyperStack.ST open Test.Lowstarize open Lib.IntTypes open Hacl.P256 open Spec.ECDSA.Test.Vectors module L = Test.Lowstarize module B = LowStar.Buffer #set-options "--fuel 0 --ifuel 0 --z3rlimit 100" noextract let sigver_vectors256_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256 noextract let sigver_vectors384_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_384 noextract let sigver_vectors512_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_512 noextract let siggen_vectors256_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_256 noextract let siggen_vectors384_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_384
{ "checked_file": "/", "dependencies": [ "Test.Lowstarize.fst.checked", "Spec.P256.fst.checked", "Spec.ECDSA.Test.Vectors.fst.checked", "prims.fst.checked", "LowStar.Printf.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.P256.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.ECDSA.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": false, "full_module": "Spec.ECDSA.Test.Vectors", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list ((((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded)
Prims.Tot
[ "total" ]
[]
[ "FStar.List.Tot.Base.map", "Spec.ECDSA.Test.Vectors.vec_SigGen", "FStar.Pervasives.Native.tuple7", "Test.Lowstarize.hex_encoded", "FStar.Pervasives.Native.Mktuple7", "Test.Lowstarize.h", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__msg'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__d", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__qx'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__qy'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__k", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__r'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__s'", "Spec.ECDSA.Test.Vectors.siggen_vectors_sha2_512" ]
[]
false
false
false
true
false
let siggen_vectors512_tmp =
List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_512
false
Hacl.Test.ECDSA.fst
Hacl.Test.ECDSA.sigver_vectors256_tmp
val sigver_vectors256_tmp : Prims.list (((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Prims.bool)
let sigver_vectors256_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256
{ "file_name": "code/tests/Hacl.Test.ECDSA.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 20, "start_col": 0, "start_line": 18 }
module Hacl.Test.ECDSA open FStar.HyperStack.ST open Test.Lowstarize open Lib.IntTypes open Hacl.P256 open Spec.ECDSA.Test.Vectors module L = Test.Lowstarize module B = LowStar.Buffer #set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
{ "checked_file": "/", "dependencies": [ "Test.Lowstarize.fst.checked", "Spec.P256.fst.checked", "Spec.ECDSA.Test.Vectors.fst.checked", "prims.fst.checked", "LowStar.Printf.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.P256.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.ECDSA.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": false, "full_module": "Spec.ECDSA.Test.Vectors", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list (((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Prims.bool)
Prims.Tot
[ "total" ]
[]
[ "FStar.List.Tot.Base.map", "Spec.ECDSA.Test.Vectors.vec_SigVer", "FStar.Pervasives.Native.tuple6", "Test.Lowstarize.hex_encoded", "Prims.bool", "FStar.Pervasives.Native.Mktuple6", "Test.Lowstarize.h", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__msg", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__qx", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__qy", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__r", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__s", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigVer__item__result", "Spec.ECDSA.Test.Vectors.sigver_vectors_sha2_256" ]
[]
false
false
false
true
false
let sigver_vectors256_tmp =
List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256
false
Hacl.Test.ECDSA.fst
Hacl.Test.ECDSA.siggen_vectors384_tmp
val siggen_vectors384_tmp : Prims.list ((((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded)
let siggen_vectors384_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_384
{ "file_name": "code/tests/Hacl.Test.ECDSA.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 41, "start_col": 0, "start_line": 39 }
module Hacl.Test.ECDSA open FStar.HyperStack.ST open Test.Lowstarize open Lib.IntTypes open Hacl.P256 open Spec.ECDSA.Test.Vectors module L = Test.Lowstarize module B = LowStar.Buffer #set-options "--fuel 0 --ifuel 0 --z3rlimit 100" noextract let sigver_vectors256_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256 noextract let sigver_vectors384_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_384 noextract let sigver_vectors512_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_512 noextract let siggen_vectors256_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_256
{ "checked_file": "/", "dependencies": [ "Test.Lowstarize.fst.checked", "Spec.P256.fst.checked", "Spec.ECDSA.Test.Vectors.fst.checked", "prims.fst.checked", "LowStar.Printf.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.P256.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.ECDSA.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": false, "full_module": "Spec.ECDSA.Test.Vectors", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list ((((((Test.Lowstarize.hex_encoded * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded) * Test.Lowstarize.hex_encoded)
Prims.Tot
[ "total" ]
[]
[ "FStar.List.Tot.Base.map", "Spec.ECDSA.Test.Vectors.vec_SigGen", "FStar.Pervasives.Native.tuple7", "Test.Lowstarize.hex_encoded", "FStar.Pervasives.Native.Mktuple7", "Test.Lowstarize.h", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__msg'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__d", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__qx'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__qy'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__k", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__r'", "Spec.ECDSA.Test.Vectors.__proj__Mkvec_SigGen__item__s'", "Spec.ECDSA.Test.Vectors.siggen_vectors_sha2_384" ]
[]
false
false
false
true
false
let siggen_vectors384_tmp =
List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_384
false
DoublyLinkedList.fst
DoublyLinkedList.dll_split_using
val dll_split_using (#t: Type) (d: dll t) (e: pointer (node t)) : StackInline (dll t * dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes))) (ensures (fun h0 (y1, y2) h1 -> Mod.modifies (Mod.loc_union (Mod.loc_union (Mod.loc_buffer (d.lhead @ h0).flink) (Mod.loc_buffer (d.ltail @ h0).blink)) (Mod.loc_union (Mod.loc_buffer (e @ h0).blink) (Mod.loc_buffer e))) h0 h1 /\ dll_valid h1 y1 /\ dll_valid h1 y2 /\ (dll_fp0 d) `loc_equiv` ((dll_fp0 y1) `Mod.loc_union` (dll_fp0 y2)) /\ (dll_fp0 y1) `Mod.loc_disjoint` (dll_fp0 y2) /\ unchanged_node_vals h0 h1 d.nodes /\ (reveal y1.nodes, reveal y2.nodes) == split_using d.nodes e))
val dll_split_using (#t: Type) (d: dll t) (e: pointer (node t)) : StackInline (dll t * dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes))) (ensures (fun h0 (y1, y2) h1 -> Mod.modifies (Mod.loc_union (Mod.loc_union (Mod.loc_buffer (d.lhead @ h0).flink) (Mod.loc_buffer (d.ltail @ h0).blink)) (Mod.loc_union (Mod.loc_buffer (e @ h0).blink) (Mod.loc_buffer e))) h0 h1 /\ dll_valid h1 y1 /\ dll_valid h1 y2 /\ (dll_fp0 d) `loc_equiv` ((dll_fp0 y1) `Mod.loc_union` (dll_fp0 y2)) /\ (dll_fp0 y1) `Mod.loc_disjoint` (dll_fp0 y2) /\ unchanged_node_vals h0 h1 d.nodes /\ (reveal y1.nodes, reveal y2.nodes) == split_using d.nodes e))
let dll_split_using (#t:Type) (d:dll t) (e:pointer (node t)) : StackInline (dll t * dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes))) (ensures (fun h0 (y1, y2) h1 -> Mod.modifies (Mod.loc_union (Mod.loc_union (Mod.loc_buffer (d.lhead@h0).flink) (Mod.loc_buffer (d.ltail@h0).blink)) (Mod.loc_union (Mod.loc_buffer (e@h0).blink) (Mod.loc_buffer e))) h0 h1 /\ dll_valid h1 y1 /\ dll_valid h1 y2 /\ dll_fp0 d `loc_equiv` (dll_fp0 y1 `Mod.loc_union` dll_fp0 y2) /\ dll_fp0 y1 `Mod.loc_disjoint` dll_fp0 y2 /\ unchanged_node_vals h0 h1 d.nodes /\ (reveal y1.nodes, reveal y2.nodes) == split_using d.nodes e)) = let h0 = ST.get () in extract_nodelist_contained h0 d.nodes (d.nodes `index_of` e); let e1 = (!*e).blink in lemma_dll_links_contained h0 d (d.nodes `index_of` e); if is_null e1 then ( let d1, d2 = empty_list, d in let h1 = ST.get () in aux_unchanged_payload_nomod h0 h1 d.nodes; _lemma_only_head_can_point_left_to_null h0 e d.nodes; d1, d2 ) else ( lemma_dll_links_contained h0 d (d.nodes `index_of` e); extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e - 1); !=|> e1; let h0' = ST.get () in !<|= e; let h1 = ST.get () in // let Frag2 p1 p2 = tot_dll_to_fragment_split h0 d e1 e in lemma_unsnoc_is_last p1.pnodes; piece_remains_valid_f h0 h0' p1; piece_remains_valid h0 h0' (Mod.loc_buffer e1) p2; piece_remains_valid h0' h1 (Mod.loc_buffer e) p1; piece_remains_valid_b h0' h1 p2; let d1 = tot_piece_to_dll h1 p1 in let d2 = tot_piece_to_dll h1 p2 in aux_unchanged_payload h0 h0' e1 d.nodes; aux_unchanged_payload h0' h1 e d.nodes; aux_unchanged_payload_transitive h0 h0' h1 d.nodes; d1, d2 )
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 2018, "start_col": 0, "start_line": 1969 }
(* Copyright 2008-2019 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 DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl let dll_valid (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d let piece_valid (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = piece_ghostly_connections p /\ piece_contained h0 p /\ piece_aa p /\ piece_conn h0 p let fragment_valid (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_ghostly_connections f /\ fragment_contained h0 f /\ fragment_aa f /\ fragment_conn h0 f /// Talk about payloads of nodes remaining constant let unchanged_node_val h0 h1 n = (h0 `contains` n ==> ((n@h0).p == (n@h1).p /\ h1 `contains` n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:nodelist 'a) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Useful operations on nodes let ( =|> ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ b@h0 == b@h1 /\ (a@h1) |>> b)) = a *= { !*a with flink = b } let ( <|= ) (#t:Type) (a:pointer (node t)) (b:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a /\ h0 `contains` b /\ Mod.loc_disjoint (Mod.loc_buffer a) (Mod.loc_buffer b))) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer b) h0 h1 /\ a@h0 == a@h1 /\ unchanged_node_val h0 h1 b /\ (b@h0).flink == (b@h1).flink /\ a <<| (b@h1))) = b *= { !*b with blink = a } let ( !=|> ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).blink == (a@h1).blink /\ (a@h1).flink == null)) = a *= { !*a with flink = null } let ( !<|= ) (#t:Type) (a:pointer (node t)) : StackInline unit (requires (fun h0 -> h0 `contains` a)) (ensures (fun h0 _ h1 -> Mod.modifies (Mod.loc_buffer a) h0 h1 /\ unchanged_node_val h0 h1 a /\ (a@h0).flink == (a@h1).flink /\ (a@h1).blink == null)) = a *= { !*a with blink = null } /// Extraction lemmas: these allow one to use one of the properties /// above, which are defined inductively, to get the property at one /// of the latter elements of the list. let rec extract_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_contained h0 nl)) (ensures (h0 `contains` nl.[i])) = match i with | 0 -> () | _ -> extract_nodelist_contained h0 (tl nl) (i - 1) let rec extract_nodelist_fp0 (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer nl.[i]))) = match i with | 0 -> () | _ -> extract_nodelist_fp0 (tl nl) (i - 1) let rec extract_nodelist_aa_r (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_r nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 right))) = match i with | 0 -> () | _ -> extract_nodelist_aa_r (tl nl) (i - 1) let rec extract_nodelist_aa_l (#t:Type) (nl:nodelist t) (i:nat{i < length nl}) : Lemma (requires (nodelist_aa_l nl)) (ensures ( let left, n, right = split3 nl i in Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 left))) (decreases (length nl)) = if i = length nl - 1 then () else ( let a, b = unsnoc nl in lemma_unsnoc_length nl; let left, n, right = split3 nl i in lemma_unsnoc_split3 nl i; // assert (append (left) (n :: (fst (unsnoc right))) == a); extract_nodelist_aa_l a i; lemma_split3_unsnoc nl i ) let rec extract_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) (i:nat{i < length nl - 1}) : Lemma (requires (nodelist_conn h0 nl)) (ensures ( (nl.[i]@h0 |>> nl.[i+1]) /\ (nl.[i] <<| nl.[i+1]@h0))) (decreases (length nl)) = match i with | 0 -> () | _ -> extract_nodelist_conn h0 (tl nl) (i - 1) /// Validity is maintained upon breaking the lists, via (hd :: tl) let rec nodelist_remains_aa_l (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa_l nl /\ length nl > 0)) (ensures (nodelist_aa_l (tl nl))) (decreases (length nl)) [SMTPat (nodelist_aa_l (tl nl))] = match nl with | [n] -> () | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; let ns', n' = unsnoc (tl nl) in // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (n' == n); // assert (ns' == tl ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns')); nodelist_remains_aa_l ns (* Rest of the validity predicates are held trivially due to their direction of definition *) /// Properties maintained upon breaking the list, via unsnoc let rec fst_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (nodelist_fp0 (fst (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> fst_unsnoc_nodelist_fp0 ns let rec snd_unsnoc_nodelist_fp0 (#t:Type) (nl:nodelist t) : Lemma (requires (length nl > 0)) (ensures (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))) [SMTPat (Mod.loc_includes (nodelist_fp0 nl) (Mod.loc_buffer (snd (unsnoc nl))))] = match nl with | [_] -> () | n :: ns -> snd_unsnoc_nodelist_fp0 ns let rec fst_unsnoc_nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_contained h0 nl /\ length nl > 0)) (ensures (nodelist_contained h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_contained h0 (tl nl) let rec fst_unsnoc_nodelist_aa (#t:Type) (nl:nodelist t) : Lemma (requires (nodelist_aa nl /\ length nl > 0)) (ensures (nodelist_aa (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_aa (tl nl); // assert (nodelist_aa_l (fst (unsnoc nl))); let n :: ns = fst (unsnoc nl) in Mod.loc_disjoint_includes (Mod.loc_buffer n) (nodelist_fp0 (tl nl)) (Mod.loc_buffer n) (nodelist_fp0 ns); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns)); // assert (nodelist_aa_r (fst (unsnoc nl))); () let rec fst_unsnoc_nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_conn h0 nl /\ length nl > 0)) (ensures (nodelist_conn h0 (fst (unsnoc nl)))) = match nl with | [_] -> () | _ -> fst_unsnoc_nodelist_conn h0 (tl nl) let fst_unsnoc_nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : Lemma (requires (nodelist_valid h0 nl /\ length nl > 0)) (ensures (nodelist_valid h0 (fst (unsnoc nl)))) = fst_unsnoc_nodelist_contained h0 nl; fst_unsnoc_nodelist_aa nl; fst_unsnoc_nodelist_conn h0 nl /// Footprints are included, even upon breaking nodelist even further let rec nodelist_includes_r_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let _, a = splitAt i nl in let _, b = splitAt j nl in Mod.loc_includes (nodelist_fp0 a) (nodelist_fp0 b))) (decreases (j - i)) = if i = j then () else ( let temp, a = splitAt i nl in lemma_splitAt nl temp a i; let temp, b = splitAt j nl in lemma_splitAt nl temp b j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (tl a == b); () ) else ( nodelist_includes_r_fp0 nl i (j - 1); nodelist_includes_r_fp0 nl (j - 1) j; let temp, c = splitAt (j - 1) nl in lemma_splitAt nl temp c (j - 1); Mod.loc_includes_trans (nodelist_fp0 a) (nodelist_fp0 c) (nodelist_fp0 b) ) ) let rec nodelist_includes_l_fp0 (#t:Type) (nl:nodelist t) (i j:nat) : Lemma (requires (i <= j /\ j < length nl)) (ensures ( let a, _ = splitAt i nl in let b, _ = splitAt j nl in Mod.loc_includes (nodelist_fp0 b) (nodelist_fp0 a))) (decreases (j - i)) = if i = j then () else ( let a, a' = splitAt i nl in lemma_splitAt nl a a' i; let b, b' = splitAt j nl in lemma_splitAt nl b b' j; if i = j - 1 then ( List.Pure.Properties.splitAt_assoc i 1 nl; // assert (b == append a [hd a']); lemma_unsnoc_append a [hd a']; // assert (snd (unsnoc b) == hd a'); // assert (fst (unsnoc b) == a); fst_unsnoc_nodelist_fp0 b ) else ( nodelist_includes_l_fp0 nl i (j - 1); nodelist_includes_l_fp0 nl (j - 1) j; let c, c' = splitAt (j - 1) nl in lemma_splitAt nl c c' (j - 1); Mod.loc_includes_trans (nodelist_fp0 b) (nodelist_fp0 c) (nodelist_fp0 a) ) ) /// Total conversions between fragments, pieces, and dlls let tot_dll_to_piece (#t:Type) (h0:heap) (d:nonempty_dll t{dll_valid h0 d}) : Tot (p:piece t{piece_valid h0 p}) = { phead = d.lhead ; ptail = d.ltail ; pnodes = d.nodes } let tot_dll_to_fragment (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d /\ d.lhead =!= null}) : Tot (f:fragment t{fragment_valid h0 f}) = Frag1 (tot_dll_to_piece h0 d) let tot_piece_to_dll (#t:Type) (h0:heap) (p:piece t{ piece_valid h0 p /\ (p.phead@h0).blink == null /\ (p.ptail@h0).flink == null}) : Tot (d:dll t{dll_valid h0 d}) = { lhead = p.phead ; ltail = p.ptail ; nodes = p.pnodes } (* The conversions piece<->fragment are trivial *) /// Properties maintained when appending nodelists let rec nodelist_append_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) (ensures (nodelist_contained h0 (append nl1 nl2))) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_append_contained h0 nl1' nl2 let rec nodelist_append_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ( loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)))) = match nl1 with | [] -> () | n :: nl1' -> nodelist_append_fp0 nl1' nl2; // assert (loc_equiv // (nodelist_fp0 (append nl1' nl2)) // (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))); // assert (loc_equiv // (nodelist_fp0 nl1) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1'))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 nl1')) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2)))); // assert (loc_equiv // (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); loc_equiv_trans (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 nl1') (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2))); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2)) // (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 (append nl1' nl2)))); () #set-options "--z3rlimit 20" let rec nodelist_append_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l nl1 /\ nodelist_aa_l nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_l (append nl1 nl2))) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; nodelist_append_fp0 nl1 nl2'; // assert (nodelist_aa_l nl2'); assert (Mod.loc_includes (nodelist_fp0 nl2) (nodelist_fp0 nl2')); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); lemma_unsnoc_is_last nl2; assert (Mod.loc_includes (nodelist_fp0 nl2) (Mod.loc_buffer n)); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl1)); // assert (loc_equiv (nodelist_fp0 (append nl1 nl2')) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2'))); nodelist_append_aa_l nl1 nl2'; // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (append nl1 nl2'))); lemma_unsnoc_append nl1 nl2; // assert (append nl1 nl2' == fst (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 (fst (unsnoc (append nl1 nl2))))); () #reset-options let rec nodelist_append_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r nl1 /\ nodelist_aa_r nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa_r (append nl1 nl2))) = match nl1 with | [] -> () | _ -> nodelist_append_fp0 (tl nl1) nl2; nodelist_append_aa_r (tl nl1) nl2 let nodelist_append_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) (ensures (nodelist_aa (append nl1 nl2))) = nodelist_append_aa_l nl1 nl2; nodelist_append_aa_r nl1 nl2 let rec nodelist_append_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_conn h0 (append nl1 nl2))) = match nl1 with | [_] -> () | _ -> nodelist_append_conn h0 (tl nl1) nl2 let nodelist_append_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ length nl1 > 0 /\ length nl2 > 0 /\ // For "= 0", it is trivially held (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) (ensures (nodelist_valid h0 (append nl1 nl2))) = nodelist_append_contained h0 nl1 nl2; nodelist_append_aa nl1 nl2; nodelist_append_conn h0 nl1 nl2 /// Useful property for for piece merging let loc_includes_union_r_inv (a b c:Mod.loc) : Lemma (requires (Mod.loc_includes a (Mod.loc_union b c))) (ensures (Mod.loc_includes a b /\ Mod.loc_includes a c)) = Mod.loc_includes_union_l b c b; Mod.loc_includes_trans a (Mod.loc_union b c) b; Mod.loc_includes_union_l b c c; Mod.loc_includes_trans a (Mod.loc_union b c) c /// Piece merging #set-options "--z3rlimit 10" val piece_merge (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Pure (piece t) (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (fun p -> (piece_valid h0 p) /\ (reveal p.pnodes == p1.pnodes `append` p2.pnodes))) let piece_merge #t h0 p1 p2 = let p = { phead = p1.phead ; ptail = p2.ptail ; pnodes = p1.pnodes ^@^ p2.pnodes } in lemma_append_last p1.pnodes p2.pnodes; nodelist_append_valid h0 p1.pnodes p2.pnodes; p #reset-options let piece_merge_fp0 (#t:Type) (h0:heap) (p1:piece t{piece_valid h0 p1}) (p2:piece t{piece_valid h0 p2}) : Lemma (requires (let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\ (a <<| b@h0) /\ Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2))) (ensures (loc_equiv (piece_fp0 (piece_merge h0 p1 p2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)))) = let p = piece_merge h0 p1 p2 in let n1, n2, n = reveal p1.pnodes, reveal p2.pnodes, reveal p.pnodes in nodelist_append_fp0 n1 n2; // assert (loc_equiv (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); // assert (hd n1 == p1.phead); // assert (Mod.loc_includes (nodelist_fp0 n1) (Mod.loc_buffer p1.phead)); // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.phead)); // assert (last n2 == p2.ptail); extract_nodelist_fp0 n2 (length n2 - 1); lemma_unsnoc_is_last n2; // assert (Mod.loc_includes (nodelist_fp0 n2) (Mod.loc_buffer p2.ptail)); extract_nodelist_fp0 n (length n - 1); lemma_unsnoc_is_last n; // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_buffer p.ptail)); loc_includes_union_r_inv (nodelist_fp0 n) (nodelist_fp0 n1) (nodelist_fp0 n2); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n1)); // assert (Mod.loc_includes (nodelist_fp0 n) (nodelist_fp0 n2)); // // assert (loc_equiv (nodelist_fp0 n) (piece_fp0 p)); extract_nodelist_fp0 n1 (length n1 - 1); lemma_unsnoc_is_last n1; // assert (loc_equiv (nodelist_fp0 n1) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 n2) (piece_fp0 p2)); // // assert (Mod.loc_includes (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2))); Mod.loc_includes_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); Mod.loc_includes_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (Mod.loc_includes (piece_fp0 p) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // // assert (Mod.loc_includes (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (nodelist_fp0 n)); loc_equiv_trans (nodelist_fp0 n) (piece_fp0 p) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)); loc_equiv_trans (nodelist_fp0 n) (Mod.loc_union (nodelist_fp0 n1) (nodelist_fp0 n2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); loc_equiv_trans (piece_fp0 p) (nodelist_fp0 n) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)) /// Fragment merging to a dll let rec fragment_defragmentable (#t:Type) (h0:heap) (f:fragment t{fragment_valid h0 f}) : GTot Type0 = let aux (p1 p2:(p:piece t{piece_valid h0 p})) = let a, b = last p1.pnodes, hd p2.pnodes in (a@h0 |>> b) /\(a <<| b@h0) in match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> aux p1 p2 | Frag3 p1 p2 p3 -> aux p1 p2 /\ aux p2 p3 let single_piece_fragment_valid (#t:Type) (h0:heap) (p:piece t) : Lemma (requires (piece_valid h0 p)) (ensures (fragment_valid h0 (Frag1 p))) = () #set-options "--z3rlimit 40 --initial_ifuel 2" let tot_defragmentable_fragment_to_dll (#t:Type) (h0:heap) (f:fragment t{ fragment_valid h0 f /\ fragment_defragmentable h0 f /\ (fragment_length f > 0 ==> (let a, b = match f with | Frag1 p1 -> p1, p1 | Frag2 p1 p2 -> p1, p2 | Frag3 p1 _ p3 -> p1, p3 in ((a.phead@h0).blink == null) /\ ((b.ptail@h0).flink == null))) }) : Tot (d:dll t{dll_valid h0 d /\ dll_fp0 d `loc_equiv` fragment_fp0 f /\ (reveal d.nodes == ( match f with | Frag0 -> [] | Frag1 p1 -> reveal p1.pnodes | Frag2 p1 p2 -> reveal p1.pnodes `append` reveal p2.pnodes | Frag3 p1 p2 p3 -> reveal p1.pnodes `append` reveal p2.pnodes `append` reveal p3.pnodes)) }) = match f with | Frag0 -> empty_list | Frag1 p1 -> tot_piece_to_dll h0 p1 | Frag2 p1 p2 -> piece_merge_fp0 h0 p1 p2; tot_piece_to_dll h0 (piece_merge h0 p1 p2) | Frag3 p1 p2 p3 -> piece_merge_fp0 h0 p1 p2; let p' = piece_merge h0 p1 p2 in piece_merge_fp0 h0 p' p3; tot_piece_to_dll h0 (piece_merge h0 p' p3) #reset-options /// Properties of nodelists maintained upon splitting nodelists let rec nodelist_split_contained (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_contained h0 (append nl1 nl2))) (ensures (nodelist_contained h0 nl1 /\ nodelist_contained h0 nl2)) = match nl1 with | [] -> () | _ :: nl1' -> nodelist_split_contained h0 nl1' nl2 let rec nodelist_split_fp0 (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = match nl1 with | [] | [_] -> () | _ -> match nl2 with | [] -> () | _ -> // assert (length nl1 > 1); // assert (length nl2 > 0); nodelist_split_fp0 (tl nl1) nl2; append_length nl1 nl2; nodelist_includes_r_fp0 (tl (append nl1 nl2)) 0 (length nl1 - 1); // assert (snd (splitAt 0 (tl (append nl1 nl2))) == tl (append nl1 nl2)); // assert (snd (splitAt (length nl1 - 1) (tl (append nl1 nl2))) == snd (splitAt (length nl1) (append nl1 nl2))); lemma_append_splitAt nl1 nl2; // assert (snd (splitAt (length nl1) (append nl1 nl2)) == nl2); // assert (Mod.loc_includes (nodelist_fp0 (tl (append nl1 nl2))) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl (append nl1 nl2)))); // assert (Mod.loc_disjoint (Mod.loc_buffer (hd nl1)) (nodelist_fp0 nl2)); // assert (Mod.loc_disjoint (nodelist_fp0 (tl nl1)) (nodelist_fp0 nl2)); Mod.loc_disjoint_union_r (nodelist_fp0 nl2) (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1)); // assert (Mod.loc_disjoint (Mod.loc_union (Mod.loc_buffer (hd nl1)) (nodelist_fp0 (tl nl1))) (nodelist_fp0 nl2)); () #set-options "--z3rlimit 30" let rec nodelist_split_fp0_equiv (#t:Type) (nl1 nl2:nodelist t) : Lemma (ensures ((loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (nodelist_fp0 nl1) (nodelist_fp0 nl2))))) = match nl1 with | [] -> () | n :: ns -> nodelist_split_fp0_equiv ns nl2; assert (loc_equiv (nodelist_fp0 (append nl1 nl2)) (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2)))); // OBSERVE assert (loc_equiv (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_union (nodelist_fp0 ns) (nodelist_fp0 nl2))) (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns)) (nodelist_fp0 nl2))) // OBSERVE let rec nodelist_split_aa_l (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_l (append nl1 nl2))) (ensures (nodelist_aa_l nl1 /\ nodelist_aa_l nl2)) (decreases (length nl2)) = match nl2 with | [] -> append_l_nil nl1 | _ -> let nl2', n = unsnoc nl2 in lemma_unsnoc_length nl2; lemma_unsnoc_append nl1 nl2; // assert (nodelist_aa_l (append nl1 nl2)); // assert (nodelist_aa_l (append nl1 nl2')); nodelist_split_aa_l nl1 nl2'; // assert (nodelist_aa_l nl2'); // assert (n == snd (unsnoc (append nl1 nl2))); // assert (n == snd (unsnoc nl2)); nodelist_append_fp0 nl1 nl2'; // assert (Mod.loc_includes (nodelist_fp0 (append nl1 nl2')) (nodelist_fp0 nl2')); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 nl2')); // assert (nodelist_aa_l nl2); () #reset-options let rec nodelist_split_aa_r (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa_r (append nl1 nl2))) (ensures (nodelist_aa_r nl1 /\ nodelist_aa_r nl2)) = match nl1 with | [] -> () | _ -> nodelist_split_aa_r (tl nl1) nl2; nodelist_append_fp0 (tl nl1) nl2 let nodelist_split_aa (#t:Type) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_aa (append nl1 nl2))) (ensures (nodelist_aa nl1 /\ nodelist_aa nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2))) = nodelist_split_fp0 nl1 nl2; nodelist_split_aa_l nl1 nl2; nodelist_split_aa_r nl1 nl2 let rec nodelist_split_conn (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires ( (nodelist_conn h0 (append nl1 nl2)) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_conn h0 nl1 /\ nodelist_conn h0 nl2 /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = match nl1 with | [_] -> () | _ -> nodelist_split_conn h0 (tl nl1) nl2 let nodelist_split_valid (#t:Type) (h0:heap) (nl1 nl2:nodelist t) : Lemma (requires (nodelist_valid h0 (append nl1 nl2) /\ length nl1 > 0 /\ length nl2 > 0)) // For "= 0", it is trivially held (ensures (nodelist_valid h0 nl1 /\ nodelist_valid h0 nl2 /\ Mod.loc_disjoint (nodelist_fp0 nl1) (nodelist_fp0 nl2) /\ (last nl1)@h0 |>> (hd nl2) /\ (last nl1) <<| (hd nl2)@h0)) = nodelist_split_contained h0 nl1 nl2; nodelist_split_aa nl1 nl2; nodelist_split_conn h0 nl1 nl2 /// Useful lemma to convert from dll_fp0 or piece_fp0 to nodelist_fp0 /// and vice-versa let dll_fp0_is_nodelist_fp0 (#t:Type) (d:dll t) : Lemma (requires (dll_ghostly_connections d)) (ensures (loc_equiv (dll_fp0 d) (nodelist_fp0 d.nodes))) = if length d.nodes > 0 then lemma_unsnoc_is_last d.nodes else () let piece_fp0_is_nodelist_fp0 (#t:Type) (p:piece t) : Lemma (requires (piece_ghostly_connections p)) (ensures (loc_equiv (piece_fp0 p) (nodelist_fp0 p.pnodes))) = lemma_unsnoc_is_last (reveal p.pnodes) /// Tot dll to fragment, with splitting #set-options "--z3rlimit 60 --initial_fuel 8 --initial_ifuel 1" let tot_dll_to_fragment_split (#t:Type) (h0:heap) (d:dll t{dll_valid h0 d}) (n1 n2:pointer (node t)) : Pure (fragment t) (requires ( n1 `memP` d.nodes /\ n2 `memP` d.nodes /\ n1@h0 |>> n2 /\ n1 <<| n2@h0)) (ensures (fun f -> fragment_valid h0 f /\ fragment_length f = 2 /\ loc_equiv (dll_fp0 d) (fragment_fp0 f) /\ (let Frag2 p1 p2 = f in reveal d.nodes == reveal p1.pnodes `append` reveal p2.pnodes))) = let split_nodes = elift2_p split_using d.nodes (hide n2) in lemma_split_using d.nodes n2; let l1 = elift1 fst split_nodes in let l2 = elift1 snd split_nodes in let p1 = { phead = d.lhead ; ptail = n1 ; pnodes = l1 } in let p2 = { phead = n2 ; ptail = d.ltail ; pnodes = l2 } in let f = Frag2 p1 p2 in dll_fp0_is_nodelist_fp0 d; // assert (loc_equiv (dll_fp0 d) (nodelist_fp0 (reveal d.nodes))); nodelist_split_fp0_equiv l1 l2; nodelist_split_valid h0 l1 l2; lemma_unsnoc_is_last l1; lemma_unsnoc_is_last l2; lemma_unsnoc_is_last (reveal d.nodes); // assert (piece_ghostly_connections p1); // assert ( n2 == hd (reveal l2) ); lemma_append_last l1 l2; // assert ( last (reveal l2) == last (append (reveal l1) (reveal l2)) ); // assert ( d.ltail == last (reveal l2) ); // assert (piece_ghostly_connections p2); // assert (fragment_ghostly_connections f); // assert (nodelist_contained h0 (reveal p1.pnodes)); // assert (nodelist_contained h0 (reveal p2.pnodes)); extract_nodelist_contained h0 l1 (length l1 - 1); // assert (h0 `contains` p1.ptail); // assert (fragment_contained h0 f); // assert (nodelist_aa (reveal p1.pnodes)); // assert (nodelist_aa (reveal p2.pnodes)); piece_fp0_is_nodelist_fp0 p1; piece_fp0_is_nodelist_fp0 p2; // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2)))); // assert (loc_equiv (nodelist_fp0 (reveal l1)) (piece_fp0 p1)); // assert (loc_equiv (nodelist_fp0 (reveal l2)) (piece_fp0 p2)); // assert (loc_equiv // (Mod.loc_union (nodelist_fp0 (reveal l1)) (nodelist_fp0 (reveal l2))) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); loc_equiv_trans (dll_fp0 d) (Mod.loc_union (nodelist_fp0 l1) (nodelist_fp0 l2)) (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2)); // assert (loc_equiv (dll_fp0 d) // (Mod.loc_union (piece_fp0 p1) (piece_fp0 p2))); // assert (Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)); // assert (fragment_aa f); // assert (nodelist_conn h0 (reveal p1.pnodes)); // assert (nodelist_conn h0 (reveal p2.pnodes)); // assert (fragment_conn h0 f); f #reset-options /// Creating a dll from a single node. Pure and ST forms of this. let tot_node_to_dll (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (dll t) (requires ( (h0 `contains` n) /\ (((n@h0).flink == null)) /\ ((n@h0).blink == null))) (ensures (fun d -> dll_valid h0 d)) = { lhead = n ; ltail = n ; nodes = ~. n } let singleton_dll (#t:Type) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (h0 `contains` n))) (ensures (fun h0 d h1 -> Mod.modifies (Mod.loc_buffer n) h0 h1 /\ dll_valid h1 d /\ unchanged_node_vals h0 h1 d.nodes /\ reveal d.nodes == [n])) = !=|> n; !<|= n; tot_node_to_dll (ST.get ()) n /// Creating a piece from a single node. let tot_node_to_piece (#t:Type) (h0:heap) (n:pointer (node t)) : Pure (piece t) (requires ( (h0 `contains` n))) (ensures (fun p -> piece_valid h0 p)) = { phead = n ; ptail = n ; pnodes = ~. n } /// Getting the "tail" of a piece let tot_piece_tail (#t:Type) (h0:heap) (p:piece t) (n:pointer (node t)) : Pure (piece t) (requires ( (piece_valid h0 p) /\ (n == (((p.phead)@h0).flink)) /\ (length p.pnodes > 1))) (ensures (fun q -> (piece_valid h0 q) /\ (reveal q.pnodes) == tl p.pnodes)) = { phead = n ; ptail = p.ptail ; pnodes = elift1_p (tot_to_gtot tl) p.pnodes } /// If a dll is valid, then both the forward and backward links of /// each of the nodes are contained in the heap, and disjoint from /// each other let lemma_dll_links_contained (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in (h0 `contains` (nodes.[i]@h0).flink) /\ (h0 `contains` (nodes.[i]@h0).blink))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else extract_nodelist_contained h0 nl (i - 1)); (if i = length nl - 1 then () else extract_nodelist_contained h0 nl (i + 1)); lemma_unsnoc_is_last nl #set-options "--z3rlimit 10 --initial_ifuel 2" let lemma_dll_links_disjoint (#t:Type) (h0:heap) (d:dll t) (i:nat) : Lemma (requires ( (dll_valid h0 d) /\ (i < length d.nodes))) (ensures ( let nodes = d.nodes in let left = (nodes.[i]@h0).blink in let right = (nodes.[i]@h0).flink in Mod.loc_disjoint (Mod.loc_buffer left) (Mod.loc_buffer right))) = let nl = reveal d.nodes in match nl with | [_] -> () | _ -> lemma_unsnoc_length nl; let node_split = splitAt i nl in lemma_splitAt nl (fst node_split) (snd node_split) i; lemma_splitAt_index_hd i nl; let l1, x :: l2 = node_split in (if i = 0 then () else extract_nodelist_conn h0 nl (i-1)); (if i = length nl - 1 then () else extract_nodelist_conn h0 nl i); (if i = 0 then () else ( if i = length nl - 1 then (lemma_unsnoc_is_last nl) else ( lemma_unsnoc_is_last l1; let left = last l1 in let right = hd l2 in lemma_splitAt_reindex_left i nl (length l1 - 1); // assert (left == (nl.[i]@h0).blink); lemma_splitAt_reindex_right i nl 1; // assert (right == (nl.[i]@h0).flink); nodelist_split_aa l1 (x :: l2); // assert (Mod.loc_disjoint (nodelist_fp0 l1) (nodelist_fp0 l2)); assert (Mod.loc_includes (nodelist_fp0 l1) (Mod.loc_buffer left)); // OBSERVE assert (Mod.loc_includes (nodelist_fp0 l2) (Mod.loc_buffer right)); // OBSERVE () ))) #reset-options /// When something unrelated to a XYZ is changed, the XYZ itself shall /// remain valid let rec nodelist_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (nl:nodelist t) : Lemma (requires ( (nodelist_valid h0 nl) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (nodelist_fp0 nl)))) (ensures (nodelist_valid h1 nl)) = match nl with | [] -> () | _ -> nodelist_remains_valid h0 h1 loc (tl nl) let piece_remains_valid (#t:Type) (h0 h1:heap) (loc:Mod.loc) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies loc h0 h1) /\ (Mod.loc_disjoint loc (piece_fp0 p)))) (ensures (piece_valid h1 p)) = nodelist_remains_valid h0 h1 loc p.pnodes /// When outward facing pointers of ends of pieces are modified, they /// still remain valid #set-options "--z3rlimit 20" let piece_remains_valid_b (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.phead) h0 h1) /\ (h1 `contains` p.phead) /\ (p.phead@h0).flink == (p.phead@h1).flink)) (ensures (piece_valid h1 p) /\ (p.ptail@h0).flink == (p.ptail@h1).flink) = let nodes = p.pnodes in if length nodes > 1 then ( nodelist_includes_r_fp0 nodes 1 (length nodes - 1); lemma_unsnoc_is_last nodes; // assert (p.ptail == nodes.[length nodes - 1]); // assert (p.ptail@h0 == p.ptail@h1); // assert (h1 `contains` p.ptail); // assert (Mod.loc_disjoint (Mod.loc_buffer p.phead) (nodelist_fp0 (tl nodes))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.phead) (tl nodes) ) else () let piece_remains_valid_f (#t:Type) (h0 h1:heap) (p:piece t) : Lemma (requires ( (piece_valid h0 p) /\ (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1) /\ (h1 `contains` p.ptail) /\ (p.ptail@h0).blink == (p.ptail@h1).blink)) (ensures (piece_valid h1 p) /\ (p.phead@h0).blink == (p.phead@h1).blink) = let nodes = reveal p.pnodes in if length nodes > 1 then ( fst_unsnoc_nodelist_valid h0 nodes; // assert (nodelist_valid h0 (fst (unsnoc nodes))); lemma_unsnoc_is_last nodes; // assert (Mod.loc_disjoint (Mod.loc_buffer p.ptail) (nodelist_fp0 (fst (unsnoc nodes)))); nodelist_remains_valid h0 h1 (Mod.loc_buffer p.ptail) (fst (unsnoc nodes)); // assert (nodelist_contained h1 (fst (unsnoc nodes))); // assert (h1 `contains` (snd (unsnoc nodes))); nodelist_append_contained h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_contained h1 (reveal p.pnodes)); // assert (piece_contained h1 p); extract_nodelist_conn h0 nodes (length nodes - 2); // let nl1 = fst (unsnoc nodes) in lemma_unsnoc_is_last (fst (unsnoc nodes)); // assert (last nl1 == nl1.[length nl1 - 1]); // assert (last nl1 == nl1.[length nodes - 2]); lemma_unsnoc_index nodes (length nodes - 2); // assert (last nl1 == nodes.[length nodes - 2]); // assert ((last (fst (unsnoc nodes)))@h0 |>> (hd [snd (unsnoc nodes)])); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); // assert (Mod.modifies (Mod.loc_buffer p.ptail) h0 h1); extract_nodelist_contained h0 nodes (length nodes - 2); // assert (h0 `contains` last (fst (unsnoc nodes))); // assert (Mod.loc_disjoint (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer p.ptail)); assert (Mod.loc_includes (nodelist_fp0 (fst (unsnoc nodes))) (Mod.loc_buffer (last (fst (unsnoc nodes))))); // OBSERVE // assert (Mod.loc_disjoint (Mod.loc_buffer (last (fst (unsnoc nodes)))) (Mod.loc_buffer p.ptail)); lemma_snoc_length (unsnoc nodes); // assert ((last (fst (unsnoc nodes)))@h0 == (last (fst (unsnoc nodes)))@h1); // assert ((last (fst (unsnoc nodes)))@h1 |>> (hd [snd (unsnoc nodes)])); // assert ((last (fst (unsnoc nodes))) <<| (hd [snd (unsnoc nodes)])@h1); nodelist_append_conn h1 (fst (unsnoc nodes)) [snd (unsnoc nodes)]; // assert (nodelist_conn h1 (reveal p.pnodes)); // assert (piece_conn h1 p); // assert ((p.phead@h0).blink == (p.phead@h1).blink); () ) else () #reset-options /// Testing is a node is within a dll or not let node_not_in_dll (#t:Type) (h0:heap) (n:pointer (node t)) (d:dll t) = let m1 = Mod.loc_buffer n in let m2 = dll_fp0 d in Mod.loc_disjoint m1 m2 /// An empty dll has no nodes let _auto_empty_dll (#t:Type) (h0:heap) (d:dll t) : Lemma (requires (dll_valid h0 d /\ (d.lhead == null \/ d.ltail == null))) (ensures (reveal d.nodes == [])) [SMTPat (dll_valid h0 d); SMTPat (reveal d.nodes)] = () /// Be able to easily reason about unchanged payloads let rec aux_unchanged_payload #t h0 h1 n0 (nl:nodelist t) : Lemma (requires (Mod.modifies (Mod.loc_buffer n0) h0 h1 /\ (n0@h0).p == (n0@h1).p /\ (nodelist_aa_r nl) /\ (n0 `memP` nl \/ Mod.loc_disjoint (Mod.loc_buffer n0) (nodelist_fp0 nl)) )) (ensures (unchanged_node_vals h0 h1 nl)) (decreases (length nl)) = match nl with | [] -> () | n :: nl' -> aux_unchanged_payload h0 h1 n0 nl'; assert (n0 `memP` nl ==> (n == n0 \/ n0 `memP` nl')); let goal () = unchanged_node_val h0 h1 n in FStar.Classical.or_elim #_ #_ #goal (fun (_:unit{n0 `memP` nl}) -> FStar.Classical.or_elim #_ #_ #goal (fun (_:unit{n == n0}) -> ()) (fun (_:unit{n0 `memP` nl'}) -> let i = nl' `index_of` n0 in extract_nodelist_fp0 nl' i)) (fun (_:unit{Mod.loc_disjoint (Mod.loc_buffer n0) (nodelist_fp0 nl)}) -> ()) let rec aux_unchanged_payload_nomod #t h0 h1 (nl:nodelist t) : Lemma (requires (Mod.modifies Mod.loc_none h0 h1)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: nl' -> aux_unchanged_payload_nomod h0 h1 nl' let rec aux_unchanged_payload_transitive #t h0 h1 h2 (nl:nodelist t) : Lemma (requires (unchanged_node_vals h0 h1 nl /\ unchanged_node_vals h1 h2 nl)) (ensures (unchanged_node_vals h0 h2 nl)) = match nl with | [] -> () | _ :: nl' -> aux_unchanged_payload_transitive h0 h1 h2 nl' let rec aux_unchanged_payload_append #t h0 h1 (nl1 nl2:nodelist t) : Lemma (requires (unchanged_node_vals h0 h1 nl1 /\ unchanged_node_vals h0 h1 nl2)) (ensures (unchanged_node_vals h0 h1 (nl1 `append` nl2))) = match nl1 with | [] -> () | n :: nl' -> aux_unchanged_payload_append h0 h1 nl' nl2 /// Now for the actual ST operations that will be exposed :) #set-options "--z3rlimit 500 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head (#t:Type) (d:dll t) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.lhead)) h0 h1 /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == n :: reveal d.nodes)) = if is_null d.lhead then ( singleton_dll n ) else ( let h = d.lhead in // let h0 = ST.get () in !<|= n; n =|> h; let h0' = ST.get () in n <|= h; let h1 = ST.get () in // aux_unchanged_payload h0 h0' n d.nodes; aux_unchanged_payload h0' h1 h d.nodes; aux_unchanged_payload_transitive h0 h0' h1 d.nodes; // let Frag1 p1 = tot_dll_to_fragment h0 d in let p = tot_node_to_piece h0 n in let f' = Frag2 p p1 in // assert (fragment_valid h1 [p]); // assert (fragment_ghostly_connections f); // assert (length f = 1); // assert (h1 `contains` (hd f).phead); piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; // assert (piece_valid h0' (hd f)); piece_remains_valid_b h0' h1 p1; // assert (h1 `contains` (hd f).ptail); // assert (nodelist_contained h1 (reveal (hd f).pnodes)); // assert (piece_contained h1 (hd f)); // assert (fragment_contained h1 f); // assert (fragment_aa f); // assert (nodelist_conn h1 (reveal (f.[0]).pnodes)); // assert (fragment_conn h1 f); // assert (fragment_valid h1 f); // assert (fragment_valid h1 f'); // assert (fragment_defragmentable h1 f'); // assert (length f' > 0); // assert (is_null ((hd f').phead@h1).blink); // assert (is_null ((last f').ptail@h0).flink); // assert (is_null ((last f').ptail@h0').flink); // assert (is_null ((last f').ptail@h1).flink); let y = tot_defragmentable_fragment_to_dll h1 f' in // assert (dll_valid h1 y); y ) #reset-options #set-options "--z3rlimit 500 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail (#t:Type) (d:dll t) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) h0 h1 /\ (dll_fp0 y `loc_equiv` B.loc_union (dll_fp0 d) (Mod.loc_buffer n)) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == snoc (reveal d.nodes, n))) = if is_null d.lhead then ( singleton_dll n ) else ( let t = d.ltail in // let h0 = ST.get () in !=|> n; t <|= n; let h0' = ST.get () in lemma_dll_links_contained h0 d (length d.nodes - 1); lemma_unsnoc_is_last d.nodes; // assert (Mod.loc_disjoint (Mod.loc_buffer (t@h0).blink) (Mod.loc_buffer n)); t =|> n; let h1 = ST.get () in // let Frag1 p1 = tot_dll_to_fragment h0 d in let p = tot_node_to_piece h0 n in let f' = Frag2 p1 p in piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; piece_remains_valid_f h0' h1 p1; let y = tot_defragmentable_fragment_to_dll h1 f' in lemma_unsnoc_is_last y.nodes; lemma_snoc_unsnoc (reveal d.nodes, n); lemma_unsnoc_index y.nodes (length (y.nodes) - 2); lemma_unsnoc_length y.nodes; aux_unchanged_payload h0 h0' n y.nodes; aux_unchanged_payload h0' h1 t y.nodes; aux_unchanged_payload_transitive h0 h0' h1 y.nodes; y ) #reset-options let _l_insert_after (x0:'a) (l:list 'a{x0 `memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = lemma_split_using l x0; split_using l x0 in assert (x0 == x1); l1 `append` (x0 :: (x :: l2)) #set-options "--z3rlimit 1000 --initial_fuel 2 --initial_ifuel 1" let dll_insert_after (#t:Type) (d:dll t) (e:pointer (node t)) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) (Mod.loc_union (Mod.loc_buffer e) (Mod.loc_buffer (e@h0).flink))) h0 h1 /\ (dll_fp0 y `loc_equiv` B.loc_union (dll_fp0 d) (Mod.loc_buffer n)) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == _l_insert_after e d.nodes n)) = let h0 = ST.get () in // assert (length d.nodes > 0); lemma_dll_links_contained h0 d (d.nodes `index_of` e); extract_nodelist_contained h0 d.nodes (d.nodes `index_of` e); let e1 = (!*e).blink in let e2 = (!*e).flink in if is_null e2 then ( let y = dll_insert_at_tail d n in assume (reveal y.nodes == _l_insert_after e (reveal d.nodes) n); y ) else ( extract_nodelist_fp0 d.nodes (d.nodes `index_of` e); lemma_unsnoc_is_last d.nodes; extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e); extract_nodelist_fp0 d.nodes (d.nodes `index_of` e + 1); if not (is_null e1) then ( extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e - 1); extract_nodelist_fp0 d.nodes (d.nodes `index_of` e - 1) ) else (); e <|= n; // let h' = ST.get () in assert (h' `contains` e2); assert (Mod.loc_disjoint (Mod.loc_buffer n) (Mod.loc_buffer e2)); n =|> e2; let h0' = ST.get () in // assert (is_not_null e1 ==> e1 == (reveal d.nodes).[reveal d.nodes `index_of` e - 1]); // assert (is_not_null e1 ==> Mod.loc_includes (nodelist_fp0 (reveal d.nodes)) (Mod.loc_buffer e1)); // assert (is_not_null e1 ==> Mod.loc_disjoint (Mod.loc_buffer n) (Mod.loc_buffer e1)); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (Mod.loc_buffer e1)); Mod.modifies_buffer_elim e1 (Mod.loc_buffer n) h0 h0'; e =|> n; let h0'' = ST.get () in // assert (h0 `contains` e2); // assert (h0' `contains` e2); // assert (e2 == (reveal d.nodes).[reveal d.nodes `index_of` e + 1]); extract_nodelist_aa_r d.nodes (d.nodes `index_of` e); lemma_split3_r_hd d.nodes (d.nodes `index_of` e); lemma_split3_append d.nodes (d.nodes `index_of` e); lemma_split3_index d.nodes (d.nodes `index_of` e); lemma_split3_length d.nodes (d.nodes `index_of` e); // assert (Mod.loc_includes (nodelist_fp0 (reveal d.nodes)) (nodelist_fp0 (let _,_,z = split3 (reveal d.nodes) (reveal d.nodes `index_of` e) in z))); // assert (Mod.loc_includes (nodelist_fp0 (let _,_,z = split3 (reveal d.nodes) (reveal d.nodes `index_of` e) in z)) (Mod.loc_buffer e2)); // assert (Mod.loc_disjoint (Mod.loc_buffer e2) (Mod.loc_buffer e)); // assert (Mod.modifies (Mod.loc_buffer e) h0' h0''); Mod.modifies_buffer_elim e2 (Mod.loc_buffer e) h0' h0''; // assert (h0'' `contains` e2); n <|= e2; let h1 = ST.get () in // // assert (e `memP` reveal d.nodes); // assert (e2 `memP` reveal d.nodes); // assert (e@h0 |>> e2 /\ e <<| e2@h0); let f = tot_dll_to_fragment_split h0 d e e2 in // assert (length f = 2); let Frag2 p1 p3 = f in // assert ([p1 ; p3] == f); let p2 = tot_node_to_piece h0 n in let f' = Frag3 p1 p2 p3 in // assert (Mod.modifies (Mod.loc_buffer n) h0 h0'); // assert (piece_valid h0 p1); // assert (loc_equiv (dll_fp0 d) (fragment_fp0 f)); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (dll_fp0 d)); // assert (Mod.loc_includes (dll_fp0 d) (fragment_fp0 f)); // assert (Mod.loc_includes (fragment_fp0 f) (piece_fp0 p1)); Mod.loc_includes_trans (dll_fp0 d) (fragment_fp0 f) (piece_fp0 p1); // assert (Mod.loc_includes (dll_fp0 d) (piece_fp0 p1)); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (piece_fp0 p1)); piece_remains_valid h0 h0' (Mod.loc_buffer n) p1; // assert (piece_valid h0 p3); Mod.loc_includes_trans (dll_fp0 d) (fragment_fp0 f) (piece_fp0 p3); // assert (Mod.loc_disjoint (Mod.loc_buffer n) (piece_fp0 p3)); piece_remains_valid h0 h0' (Mod.loc_buffer n) p3; piece_remains_valid_f h0' h0'' p1; // assert (Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p3)); piece_remains_valid h0' h0'' (piece_fp0 p1) p3; piece_remains_valid h0'' h1 (piece_fp0 p3) p1; piece_remains_valid_b h0'' h1 p3; // assert ([p2 ; p3] == append [p2] [p3]); // assert (f' == append [p1] [p2 ; p3]); // // assert (fragment_valid h1 f'); assert (fragment_defragmentable h1 (Frag2 p2 p3)); // OBSERVE // assert (fragment_defragmentable h1 f'); // assert (length f' > 0); // assert (is_null ((hd f').phead@h1).blink); // lemma_unsnoc_is_last f'; // assert (last f' == p3); // assert (is_null ((last f').ptail@h1).flink); let y = tot_defragmentable_fragment_to_dll h1 f' in assume (n `memP` y.nodes); assume (e `memP` y.nodes); assume (e2 `memP` y.nodes); aux_unchanged_payload h0 h0' n y.nodes; aux_unchanged_payload h0' h0'' e y.nodes; aux_unchanged_payload h0'' h1 e2 y.nodes; aux_unchanged_payload_transitive h0 h0' h0'' y.nodes; aux_unchanged_payload_transitive h0 h0'' h1 y.nodes; assume (reveal y.nodes == _l_insert_after e (reveal d.nodes) n); y ) #reset-options let _l_insert_before (x0:'a) (l:list 'a{x0 `memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = split_using l x0 in l1 `append` (x :: l2) #set-options "--z3rlimit 50" let dll_insert_before (#t:Type) (d:dll t) (e:pointer (node t)) (n:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes) /\ (h0 `contains` n) /\ (node_not_in_dll h0 n d))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_union (Mod.loc_union (Mod.loc_buffer n) (Mod.loc_buffer d.ltail)) // this is needed due to using "after" // TODO: Figure out a way to remove it (Mod.loc_union (Mod.loc_buffer (e@h0).blink) (Mod.loc_buffer e)))) h0 h1 /\ (dll_fp0 y `loc_equiv` B.loc_union (dll_fp0 d) (Mod.loc_buffer n)) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == _l_insert_before e d.nodes n)) = let h0 = ST.get () in extract_nodelist_contained h0 d.nodes (d.nodes `index_of` e); let e1 = (!*e).blink in lemma_dll_links_contained h0 d (d.nodes `index_of` e); if is_null e1 then ( let y = dll_insert_at_head d n in assume (reveal y.nodes == _l_insert_before e d.nodes n); y ) else ( extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e - 1); let y = dll_insert_after d e1 n in assume (reveal y.nodes == _l_insert_before e (reveal d.nodes) n); y ) #reset-options unfold let _aux_fp_split_by_node (d0 d1:dll 'a) (n:pointer (node 'a)) = dll_fp0 d0 `loc_equiv` B.loc_union (dll_fp0 d1) (Mod.loc_buffer n) /\ dll_fp0 d1 `B.loc_disjoint` Mod.loc_buffer n #set-options "--z3rlimit 20" let dll_remove_head (#t:Type) (d:dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (length d.nodes > 0))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_buffer (d.lhead@h0).flink) h0 h1 /\ _aux_fp_split_by_node d y d.lhead /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == tl d.nodes)) = let h0 = ST.get () in let e = d.lhead in let e2 = (!*e).flink in if is_null e2 then ( empty_list ) else ( !<|= e2; let h1 = ST.get () in let f = tot_dll_to_fragment_split h0 d e e2 in let Frag2 p1 p2 = f in // assert (p1.phead == e); // assert (p1.ptail == e); let f' = Frag1 p2 in piece_remains_valid_b h0 h1 p2; let y = tot_defragmentable_fragment_to_dll h1 f' in aux_unchanged_payload h0 h1 e2 d.nodes; y ) #reset-options let rec _lemma_only_head_can_point_left_to_null (#t:Type) (h0:heap) (e:pointer (node t)) (l:nodelist t) : Lemma (requires (e `memP` l /\ (e@h0).blink == null /\ nodelist_conn h0 l)) (ensures (e == hd l)) = match l with | [_] -> () | _ -> FStar.Classical.or_elim #(e == hd l) #(e =!= hd l) #(fun () -> e == hd l) (fun _ -> ()) (fun _ -> _lemma_only_head_can_point_left_to_null h0 e (tl l); extract_nodelist_conn h0 l 0) let rec _lemma_only_tail_can_point_right_to_null (#t:Type) (h0:heap) (e:pointer (node t)) (l:nodelist t) : Lemma (requires (e `memP` l /\ (e@h0).flink == null /\ nodelist_conn h0 l)) (ensures (e == last l)) = match l with | [_] -> () | _ -> _lemma_only_tail_can_point_right_to_null h0 e (tl l) let rec _lemma_all_nodes_are_unique (#t:Type) (h0:heap) (l:nodelist t) (i j:nat) : Lemma (requires ( (nodelist_conn h0 l) /\ (i < length l) /\ (j < length l) /\ (((hd l)@h0).blink == null) /\ (index l i == index l j))) (ensures (i = j)) = match i, j with | 0, 0 -> () | 0, _ -> extract_nodelist_conn h0 l (j - 1) | _, 0 -> extract_nodelist_conn h0 l (i - 1) | _ -> extract_nodelist_conn h0 l (i - 1); extract_nodelist_conn h0 l (j - 1); _lemma_all_nodes_are_unique h0 l (i - 1) (j - 1) #set-options "--z3rlimit 50" let dll_remove_tail (#t:Type) (d:dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (length d.nodes > 0))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_buffer (d.ltail@h0).blink) h0 h1 /\ _aux_fp_split_by_node d y d.ltail /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == fst (unsnoc (reveal d.nodes)))) = let h0 = ST.get () in let e = d.ltail in let e1 = (!*e).blink in lemma_dll_links_contained h0 d (length d.nodes - 1); lemma_unsnoc_is_last d.nodes; if is_null e1 then ( _lemma_only_head_can_point_left_to_null h0 e d.nodes; empty_list ) else ( extract_nodelist_contained h0 d.nodes (length (d.nodes) - 2); extract_nodelist_conn h0 d.nodes (length (d.nodes) - 2); // assert (e == (reveal d.nodes).[length (reveal d.nodes) - 1]); // assert (e1 == (reveal d.nodes).[length (reveal d.nodes) - 2]); !=|> e1; let h1 = ST.get () in let f = tot_dll_to_fragment_split h0 d e1 e in let Frag2 p1 p2 = f in lemma_snoc_length (reveal p1.pnodes, e); // assert (reveal p1.pnodes == fst (unsnoc (reveal d.nodes))); let f' = Frag1 p1 in piece_remains_valid_f h0 h1 p1; let y = tot_defragmentable_fragment_to_dll h1 f' in aux_unchanged_payload h0 h1 e1 (d.nodes); // assert (reveal y.nodes == reveal p1.pnodes); y ) #reset-options let _l_remove_mid (l:list 'a{length l > 0}) (x:'a {x `memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = lemma_split_using l x; split_using l x in assert (x == x0); l1 `append` l2 #set-options "--z3rlimit 400 --initial_fuel 2 --initial_ifuel 2" let dll_remove_node (#t:Type) (d:dll t) (e:pointer (node t)) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_union (Mod.loc_buffer (d.lhead@h0).flink) (Mod.loc_buffer (d.ltail@h0).blink)) (Mod.loc_union (Mod.loc_buffer (e@h0).blink) (Mod.loc_buffer (e@h0).flink))) h0 h1 /\ _aux_fp_split_by_node d y e /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 d.nodes /\ reveal y.nodes == _l_remove_mid d.nodes e)) = let h0 = ST.get () in extract_nodelist_contained h0 d.nodes (d.nodes `index_of` e); let e1 = (!*e).blink in let e2 = (!*e).flink in lemma_dll_links_contained h0 d (d.nodes `index_of` e); if is_null e1 then ( _lemma_only_head_can_point_left_to_null h0 e d.nodes; dll_remove_head d ) else if is_null e2 then ( _lemma_only_tail_can_point_right_to_null h0 e d.nodes; let y = dll_remove_tail d in let h1 = ST.get () in // assume (unchanged_node_vals h0 h1 (reveal d.nodes)); assume (reveal y.nodes == _l_remove_mid d.nodes e); y ) else ( admit (); lemma_dll_links_contained h0 d (d.nodes `index_of` e); extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e - 1); extract_nodelist_aa_r d.nodes (d.nodes `index_of` e - 1); extract_nodelist_fp0 d.nodes (d.nodes `index_of` e); lemma_dll_links_disjoint h0 d (d.nodes `index_of` e); e1 =|> e2; let h0' = ST.get () in e1 <|= e2; let h1 = ST.get () in // assert (e1 == (reveal d.nodes).[reveal d.nodes `index_of` e - 1]); // assert (e1 `memP` reveal d.nodes); // assert (e1@h0 |>> e); let f = tot_dll_to_fragment_split h0 d e1 e in let Frag2 p1 p2 = f in let p2' = tot_piece_tail h0 p2 e2 in let f' = Frag2 p1 p2' in piece_remains_valid_f h0 h0' p1; piece_remains_valid h0' h1 (Mod.loc_buffer e2) p1; piece_remains_valid h0 h0' (Mod.loc_buffer e1) p2'; piece_remains_valid_b h0' h1 p2'; let y = tot_defragmentable_fragment_to_dll h1 f' in // assert (dll_valid h1 y); assume (_aux_fp_split_by_node d y e); assume (unchanged_node_vals h0 h1 d.nodes); assume (reveal y.nodes == _l_remove_mid d.nodes e); y ) #reset-options #set-options "--z3rlimit 10 --max_fuel 2 --max_ifuel 1" let dll_append (#t:Type) (d1 d2:dll t) : StackInline (dll t) (requires (fun h0 -> (dll_valid h0 d1) /\ (dll_valid h0 d2) /\ (dll_fp0 d1 `Mod.loc_disjoint` dll_fp0 d2))) (ensures (fun h0 y h1 -> Mod.modifies (Mod.loc_union (Mod.loc_buffer d1.ltail) (Mod.loc_buffer d2.lhead)) h0 h1 /\ dll_fp0 y `loc_equiv` (dll_fp0 d1 `B.loc_union` dll_fp0 d2) /\ dll_valid h1 y /\ unchanged_node_vals h0 h1 y.nodes /\ reveal y.nodes == d1.nodes `append` d2.nodes)) = let h0 = ST.get () in if is_null d1.lhead then ( let y = d2 in let h1 = ST.get () in aux_unchanged_payload_nomod h0 h1 y.nodes; y ) else ( if is_null d2.lhead then ( let y = d1 in let h1 = ST.get () in aux_unchanged_payload_nomod h0 h1 y.nodes; append_l_nil y.nodes; y ) else ( let n1 = d1.ltail in let n2 = d2.lhead in n1 =|> n2; let h0' = ST.get () in n1 <|= n2; let h1 = ST.get () in // let p1 = tot_dll_to_piece h0 d1 in let p2 = tot_dll_to_piece h0 d2 in let f' = Frag2 p1 p2 in piece_remains_valid_f h0 h0' p1; piece_remains_valid h0 h0' (Mod.loc_buffer n1) p2; piece_remains_valid h0' h1 (Mod.loc_buffer n2) p1; piece_remains_valid_b h0' h1 p2; let y = tot_defragmentable_fragment_to_dll h1 f' in lemma_unsnoc_is_last d1.nodes; aux_unchanged_payload h0 h0' n1 d1.nodes; aux_unchanged_payload h0 h0' n1 d2.nodes; aux_unchanged_payload h0' h1 n2 d1.nodes; aux_unchanged_payload h0' h1 n2 d2.nodes; aux_unchanged_payload_transitive h0 h0' h1 d1.nodes; aux_unchanged_payload_transitive h0 h0' h1 d2.nodes; aux_unchanged_payload_append h0 h1 d1.nodes d2.nodes; y ) ) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "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": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 2, "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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedList.dll t -> e: LowStar.Buffer.pointer (DoublyLinkedList.node t) -> FStar.HyperStack.ST.StackInline (DoublyLinkedList.dll t * DoublyLinkedList.dll t)
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedList.dll", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "DoublyLinkedList._lemma_only_head_can_point_left_to_null", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "DoublyLinkedList.aux_unchanged_payload_nomod", "FStar.Pervasives.Native.tuple2", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "DoublyLinkedList.empty_list", "Prims.bool", "DoublyLinkedList.piece", "DoublyLinkedList.aux_unchanged_payload_transitive", "DoublyLinkedList.aux_unchanged_payload", "DoublyLinkedList.dll_valid", "DoublyLinkedList.tot_piece_to_dll", "DoublyLinkedList.piece_remains_valid_b", "DoublyLinkedList.piece_remains_valid", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.piece_remains_valid_f", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "DoublyLinkedList.fragment", "DoublyLinkedList.tot_dll_to_fragment_split", "DoublyLinkedList.op_Bang_Less_Bar_Equals", "DoublyLinkedList.op_Bang_Equals_Bar_Greater", "DoublyLinkedList.extract_nodelist_conn", "Prims.op_Subtraction", "FStar.List.Tot.Properties.index_of", "DoublyLinkedList.lemma_dll_links_contained", "LowStar.Monotonic.Buffer.is_null", "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.__proj__Mknode__item__blink", "LowStar.BufferOps.op_Bang_Star", "DoublyLinkedList.extract_nodelist_contained", "Prims.l_and", "FStar.List.Tot.Base.memP", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedList.op_At", "DoublyLinkedList.__proj__Mkdll__item__lhead", "DoublyLinkedList.__proj__Mkdll__item__ltail", "DoublyLinkedList.loc_equiv", "DoublyLinkedList.dll_fp0", "LowStar.Monotonic.Buffer.loc_disjoint", "DoublyLinkedList.unchanged_node_vals", "Prims.eq2", "Prims.list", "FStar.List.Tot.Properties.split_using" ]
[]
false
true
false
false
false
let dll_split_using (#t: Type) (d: dll t) (e: pointer (node t)) : StackInline (dll t * dll t) (requires (fun h0 -> (dll_valid h0 d) /\ (e `memP` d.nodes))) (ensures (fun h0 (y1, y2) h1 -> Mod.modifies (Mod.loc_union (Mod.loc_union (Mod.loc_buffer (d.lhead @ h0).flink) (Mod.loc_buffer (d.ltail @ h0).blink)) (Mod.loc_union (Mod.loc_buffer (e @ h0).blink) (Mod.loc_buffer e))) h0 h1 /\ dll_valid h1 y1 /\ dll_valid h1 y2 /\ (dll_fp0 d) `loc_equiv` ((dll_fp0 y1) `Mod.loc_union` (dll_fp0 y2)) /\ (dll_fp0 y1) `Mod.loc_disjoint` (dll_fp0 y2) /\ unchanged_node_vals h0 h1 d.nodes /\ (reveal y1.nodes, reveal y2.nodes) == split_using d.nodes e)) =
let h0 = ST.get () in extract_nodelist_contained h0 d.nodes (d.nodes `index_of` e); let e1 = (!*e).blink in lemma_dll_links_contained h0 d (d.nodes `index_of` e); if is_null e1 then (let d1, d2 = empty_list, d in let h1 = ST.get () in aux_unchanged_payload_nomod h0 h1 d.nodes; _lemma_only_head_can_point_left_to_null h0 e d.nodes; d1, d2) else (lemma_dll_links_contained h0 d (d.nodes `index_of` e); extract_nodelist_conn h0 d.nodes (d.nodes `index_of` e - 1); !=|>e1; let h0' = ST.get () in !<|=e; let h1 = ST.get () in let Frag2 p1 p2 = tot_dll_to_fragment_split h0 d e1 e in lemma_unsnoc_is_last p1.pnodes; piece_remains_valid_f h0 h0' p1; piece_remains_valid h0 h0' (Mod.loc_buffer e1) p2; piece_remains_valid h0' h1 (Mod.loc_buffer e) p1; piece_remains_valid_b h0' h1 p2; let d1 = tot_piece_to_dll h1 p1 in let d2 = tot_piece_to_dll h1 p2 in aux_unchanged_payload h0 h0' e1 d.nodes; aux_unchanged_payload h0' h1 e d.nodes; aux_unchanged_payload_transitive h0 h0' h1 d.nodes; d1, d2)
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.op_String_Access
val op_String_Access : s: Lib.Sequence.lseq a len -> i: (n: Prims.nat{n <= Prims.pow2 32 - 1}){i < len} -> r: a{r == FStar.Seq.Base.index (Lib.Sequence.to_seq s) i}
let op_String_Access #a #len = LSeq.index #a #len
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 119, "start_col": 0, "start_line": 119 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Lib.Sequence.lseq a len -> i: (n: Prims.nat{n <= Prims.pow2 32 - 1}){i < len} -> r: a{r == FStar.Seq.Base.index (Lib.Sequence.to_seq s) i}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_nat", "Lib.Sequence.index", "Lib.Sequence.lseq", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.index", "Lib.Sequence.to_seq" ]
[]
false
false
false
false
false
let ( .[] ) #a #len =
LSeq.index #a #len
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_eval_index
val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t))
val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t))
let bn_eval_index #t #len b i = let pbits = bits t in calc (==) { bn_v b / pow2 (pbits * i) % pow2 pbits; (==) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; (==) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; (==) { bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i)) } bn_v (slice b i len) % pow2 pbits; (==) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; (==) { bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0 } v b.[i] % pow2 pbits; (==) { Math.Lemmas.modulo_lemma (v b.[i]) (pow2 pbits) } v b.[i]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[i])
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 219, "start_col": 0, "start_line": 199 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i)) let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Prims.nat{i < len} -> FStar.Pervasives.Lemma (ensures Lib.IntTypes.v b.[ i ] == Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 (Lib.IntTypes.bits t * i) % Prims.pow2 (Lib.IntTypes.bits t))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.op_Division", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Prims.op_Addition", "Lib.Sequence.slice", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.squash", "FStar.Math.Lemmas.division_addition_lemma", "FStar.Math.Lemmas.small_division_lemma_1", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "FStar.Math.Lemmas.modulo_addition_lemma", "FStar.Seq.Base.lemma_index_slice", "Hacl.Spec.Bignum.Definitions.bn_eval1", "FStar.Math.Lemmas.modulo_lemma", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_eval_index #t #len b i =
let pbits = bits t in calc ( == ) { bn_v b / pow2 (pbits * i) % pow2 pbits; ( == ) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; ( == ) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; ( == ) { (bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i))) } bn_v (slice b i len) % pow2 pbits; ( == ) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; ( == ) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; ( == ) { (bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0) } v b.[ i ] % pow2 pbits; ( == ) { Math.Lemmas.modulo_lemma (v b.[ i ]) (pow2 pbits) } v b.[ i ]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[ i ])
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.width
val width (s: field_spec) : Vec.lanes
val width (s: field_spec) : Vec.lanes
let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 37, "start_col": 0, "start_line": 33 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> Hacl.Spec.Poly1305.Vec.lanes
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Spec.Poly1305.Vec.lanes" ]
[]
false
false
false
true
false
let width (s: field_spec) : Vec.lanes =
match s with | M32 -> 1 | M128 -> 2 | M256 -> 4
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.nlimb
val nlimb (s: field_spec) : size_t
val nlimb (s: field_spec) : size_t
let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 65, "start_col": 0, "start_line": 61 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> Lib.IntTypes.size_t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t" ]
[]
false
false
false
true
false
let nlimb (s: field_spec) : size_t =
match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.feval
val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s))
val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s))
let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 116, "start_col": 0, "start_line": 112 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
h: FStar.Monotonic.HyperStack.mem -> e: Hacl.Impl.Poly1305.Fields.felem s -> Prims.GTot (Lib.Sequence.lseq Spec.Poly1305.felem (Hacl.Impl.Poly1305.Fields.width s))
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.feval", "Lib.Sequence.lseq", "Spec.Poly1305.felem", "Hacl.Impl.Poly1305.Fields.width" ]
[]
false
false
false
false
false
let feval #s h e =
match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.fas_nat
val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s))
val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s))
let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 108, "start_col": 0, "start_line": 104 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
h: FStar.Monotonic.HyperStack.mem -> e: Hacl.Impl.Poly1305.Fields.felem s -> Prims.GTot (Lib.Sequence.lseq Prims.nat (Hacl.Impl.Poly1305.Fields.width s))
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.fas_nat", "Lib.Sequence.lseq", "Prims.nat", "Hacl.Impl.Poly1305.Fields.width" ]
[]
false
false
false
false
false
let fas_nat #s h e =
match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.felem_fits
val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0
val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0
let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 100, "start_col": 0, "start_line": 96 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
h: FStar.Monotonic.HyperStack.mem -> f: Hacl.Impl.Poly1305.Fields.felem s -> m: Hacl.Spec.Poly1305.Field32xN.scale32_5 -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Spec.Poly1305.Field32xN.scale32_5", "Hacl.Impl.Poly1305.Field32xN.felem_fits" ]
[]
false
false
false
false
true
let felem_fits #s h f m =
match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.nelem
val nelem (s: field_spec) : size_t
val nelem (s: field_spec) : size_t
let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 79, "start_col": 0, "start_line": 75 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> Lib.IntTypes.size_t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t" ]
[]
false
false
false
true
false
let nelem (s: field_spec) : size_t =
match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.wide
val wide : s: Hacl.Impl.Poly1305.Fields.field_spec -> Type0
let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 58, "start_col": 0, "start_line": 54 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Spec.Poly1305.Field32xN.uint64xN" ]
[]
false
false
false
true
true
let wide (s: field_spec) =
match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.limb
val limb : s: Hacl.Impl.Poly1305.Fields.field_spec -> Type0
let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 44, "start_col": 0, "start_line": 40 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Spec.Poly1305.Field32xN.uint64xN" ]
[]
false
false
false
true
true
let limb (s: field_spec) =
match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.limb_zero
val limb_zero (s: field_spec) : limb s
val limb_zero (s: field_spec) : limb s
let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 51, "start_col": 0, "start_line": 47 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> Hacl.Impl.Poly1305.Fields.limb s
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Spec.Poly1305.Field32xN.zero", "Hacl.Impl.Poly1305.Fields.limb" ]
[]
false
false
false
false
false
let limb_zero (s: field_spec) : limb s =
match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.precomplen
val precomplen (s: field_spec) : size_t
val precomplen (s: field_spec) : size_t
let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 86, "start_col": 0, "start_line": 82 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> Lib.IntTypes.size_t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t" ]
[]
false
false
false
true
false
let precomplen (s: field_spec) : size_t =
match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.blocklen
val blocklen (s: field_spec) : r: size_t{0 < v r /\ v r == width s * S.size_block}
val blocklen (s: field_spec) : r: size_t{0 < v r /\ v r == width s * S.size_block}
let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 72, "start_col": 0, "start_line": 68 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> r: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v r /\ Lib.IntTypes.v r == Hacl.Impl.Poly1305.Fields.width s * Spec.Poly1305.size_block }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "FStar.Mul.op_Star", "Hacl.Impl.Poly1305.Fields.width", "Spec.Poly1305.size_block" ]
[]
false
false
false
false
false
let blocklen (s: field_spec) : r: size_t{0 < v r /\ v r == width s * S.size_block} =
match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul
false
EverParse3d.Actions.Base.fsti
EverParse3d.Actions.Base.is_range_okay
val is_range_okay : size: FStar.UInt32.t -> offset: FStar.UInt32.t -> access_size: FStar.UInt32.t -> Prims.bool
let is_range_okay = EverParse3d.ErrorCode.is_range_okay
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 55, "end_line": 25, "start_col": 0, "start_line": 25 }
(* Copyright 2019 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 EverParse3d.Actions.Base module Cast = FStar.Int.Cast open EverParse3d.Prelude module U32 = FStar.UInt32 module U64 = FStar.UInt64 module CP = EverParse3d.CopyBuffer inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "EverParse3d.Prelude.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked" ], "interface_file": false, "source_file": "EverParse3d.Actions.Base.fsti" }
[ { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
size: FStar.UInt32.t -> offset: FStar.UInt32.t -> access_size: FStar.UInt32.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.ErrorCode.is_range_okay" ]
[]
false
false
false
true
false
let is_range_okay =
EverParse3d.ErrorCode.is_range_okay
false
EverParse3d.Actions.Base.fsti
EverParse3d.Actions.Base.validator
val validator : p: EverParse3d.Prelude.parser k t -> Type0
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t) = validate_with_action_t p true_inv disjointness_trivial eloc_none true
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 73, "end_line": 633, "start_col": 0, "start_line": 632 }
(* Copyright 2019 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 EverParse3d.Actions.Base module Cast = FStar.Int.Cast open EverParse3d.Prelude module U32 = FStar.UInt32 module U64 = FStar.UInt64 module CP = EverParse3d.CopyBuffer inline_for_extraction noextract let is_range_okay = EverParse3d.ErrorCode.is_range_okay [@@erasable] val slice_inv : Type u#1 val inv_implies (inv0 inv1: slice_inv) : Tot prop val true_inv : slice_inv val conj_inv (i0 i1: slice_inv) : Tot slice_inv [@@erasable] val eloc : Type0 val eloc_union (l1 l2: eloc) : Tot eloc val eloc_none : eloc val eloc_includes (l1 l2: eloc) : Tot prop val eloc_disjoint (l1 l2: eloc) : Tot prop val inv_implies_refl (inv: slice_inv) : Tot (squash (inv `inv_implies` inv)) val inv_implies_true (inv0:slice_inv) : Tot (squash (inv0 `inv_implies` true_inv)) val inv_implies_conj (inv0 inv1 inv2: slice_inv) (h01: squash (inv0 `inv_implies` inv1)) (h02: squash (inv0 `inv_implies` inv2)) : Tot (squash (inv0 `inv_implies` (inv1 `conj_inv` inv2))) val conj_inv_true_left_unit (inv:slice_inv) : Tot (squash (true_inv `conj_inv` inv == inv)) val conj_inv_true_right_unit (inv:slice_inv) : Tot (squash (inv `conj_inv` true_inv == inv)) val eloc_includes_none (l1:eloc) : Tot (squash (l1 `eloc_includes` eloc_none)) val eloc_includes_union (l0: eloc) (l1 l2: eloc) (h01: squash (l0 `eloc_includes` l1)) (h02: squash (l0 `eloc_includes` l2)) : Tot (squash (l0 `eloc_includes` (l1 `eloc_union` l2))) val eloc_includes_refl (l: eloc) : Tot (squash (l `eloc_includes` l)) val eloc_union_none_left_unit (l:eloc) : Tot (squash (eloc_none `eloc_union` l == l)) val eloc_union_none_right_unit (l:eloc) : Tot (squash (l `eloc_union` eloc_none == l)) [@@erasable] val disjointness_pre : Type u#1 val disjointness_trivial : disjointness_pre val disjoint (l1 l2:eloc) : disjointness_pre val conj_disjointness (d0 d1:disjointness_pre) : disjointness_pre val imp_disjointness (d1 d2:disjointness_pre) : prop val disjoint_none_r (l:eloc) : squash (disjoint l eloc_none == disjointness_trivial) val disjoint_none_l (l:eloc) : squash (disjoint eloc_none l == disjointness_trivial) val conj_disjointness_trivial_left_unit (d:disjointness_pre) : squash ((disjointness_trivial `conj_disjointness` d) == d) val conj_disjointness_trivial_right_unit (d:disjointness_pre) : squash ((d `conj_disjointness` disjointness_trivial) == d) val imp_disjointness_refl (d:disjointness_pre) : squash (imp_disjointness d d) val index_equations (_:unit) : Lemma (ensures ( //true_inv left unit (forall (d:slice_inv). {:pattern (true_inv `conj_inv` d)} (true_inv `conj_inv` d) == d) /\ //true_inv right unit (forall (d:slice_inv). {:pattern (d `conj_inv` true_inv)} (d `conj_inv` true_inv) == d) /\ //eloc_none left unit (forall (l:eloc). {:pattern (l `eloc_union` eloc_none)} (l `eloc_union` eloc_none) == l) /\ //eloc_none right unit (forall (l:eloc). {:pattern (eloc_none `eloc_union` l)} (eloc_none `eloc_union` l) == l) /\ //disjoint eloc_none right trivial (forall (l:eloc). {:pattern (disjoint l eloc_none)} (disjoint l eloc_none) == disjointness_trivial) /\ //disjoint eloc_none left trivial (forall (l:eloc). {:pattern (disjoint eloc_none l)} (disjoint eloc_none l) == disjointness_trivial) /\ //disjointness_pre right unit (forall (d:disjointness_pre). {:pattern (conj_disjointness d disjointness_trivial)} (conj_disjointness d disjointness_trivial) == d) /\ //disjointness_pre left unit (forall (d:disjointness_pre). {:pattern (conj_disjointness disjointness_trivial d)} (conj_disjointness disjointness_trivial d) == d) /\ //imp_disjointness refl (forall (d:disjointness_pre). {:pattern (imp_disjointness d d)} imp_disjointness d d) /\ //inv_implies refl (forall (i:slice_inv). {:pattern (inv_implies i i)} inv_implies i i) /\ //inv_implies true_inv right trivial (forall (i:slice_inv). {:pattern (inv_implies i true_inv)} inv_implies i true_inv) /\ //inv_implies_conj (forall (i0 i1 i2:slice_inv). {:pattern (i0 `inv_implies` (i1 `conj_inv` i2))} (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2))) /\ //eloc_includes_none (forall (l:eloc). {:pattern (l `eloc_includes` eloc_none)} l `eloc_includes` eloc_none) /\ //eloc_includes_union (forall (l0 l1 l2:eloc). {:pattern (l0 `eloc_includes` (l1 `eloc_union` l2))} (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2))) /\ //eloc_includes_refl (forall (l:eloc). {:pattern (l `eloc_includes` l)} (l `eloc_includes` l)) )) inline_for_extraction noextract val bpointer (a: Type0) : Tot Type0 val ptr_loc (#a: _) (x: bpointer a) : Tot eloc val ptr_inv (#a: _) (x: bpointer a) : Tot slice_inv inline_for_extraction noextract val action (liveness_inv:slice_inv) (disj:disjointness_pre) (modifies_l:eloc) (on_success:bool) (a:Type) : Type0 inline_for_extraction noextract val validate_with_action_t (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:Type) (p:parser k t) (liveness_inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type0 inline_for_extraction noextract val validate_eta (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv disj l allow_reading) : Tot (validate_with_action_t p inv disj l allow_reading) inline_for_extraction noextract val act_with_comment (s: string) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#b:_) (res:Type) (a: action inv disj l b res) : Tot (action inv disj l b res) inline_for_extraction noextract val leaf_reader (#nz:bool) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (p: parser k t) : Type u#0 inline_for_extraction noextract val validate_with_success_action (name: string) (#nz:bool) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#allow_reading:bool) (v1:validate_with_action_t p1 inv1 disj1 l1 allow_reading) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#b:bool) (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false inline_for_extraction noextract val validate_with_error_handler (typename: string) (fieldname: string) (#nz: _) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1: Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj l1 ar) : validate_with_action_t p1 inv1 disj l1 ar inline_for_extraction noextract val validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true inline_for_extraction noextract val validate_pair (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#allow_reading1:bool) (v1:validate_with_action_t p1 inv1 disj1 l1 allow_reading1) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:Type) (#[@@@erasable] p2:parser k2 t2) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:validate_with_action_t p2 inv2 disj2 l2 allow_reading2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false inline_for_extraction noextract val validate_dep_pair (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:t1 -> Type) (#[@@@erasable] p2:(x:t1 -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false inline_for_extraction noextract val validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#[@@@erasable] inv1':slice_inv) (#[@@@erasable] disj1':disjointness_pre) (#[@@@erasable] l1':eloc) (#b:_) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false inline_for_extraction noextract val validate_dep_pair_with_action (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (#[@@@erasable] inv1':slice_inv) (#[@@@erasable] disj1':disjointness_pre) (#[@@@erasable] l1':eloc) (#b:_) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:t1 -> Type) (#[@@@erasable] p2:(x:t1 -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:_) (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false inline_for_extraction noextract val validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false inline_for_extraction noextract val validate_filter (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : validate_with_action_t (p `parse_filter` f) inv disj l false inline_for_extraction noextract val validate_filter_with_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] disja:disjointness_pre) (#[@@@erasable] la:eloc) (a: t -> action inva disja la b bool) : validate_with_action_t #nz (p `parse_filter` f) (conj_inv inv inva) (conj_disjointness disj disja) (eloc_union l la) false inline_for_extraction noextract val validate_with_dep_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] disja:disjointness_pre) (#[@@@erasable] la:eloc) (a: t -> action inva disja la b bool) : validate_with_action_t #nz p (conj_inv inv inva) (conj_disjointness disj disja) (eloc_union l la) false inline_for_extraction noextract val validate_weaken_left (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (#nz':_) (#wk': _) (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv disj l allow_reading inline_for_extraction noextract val validate_weaken_right (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (#nz':_) (#wk': _) (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv disj l allow_reading inline_for_extraction noextract val validate_impos (_:unit) : validate_with_action_t (parse_impos ()) true_inv disjointness_trivial eloc_none true noextract inline_for_extraction val validate_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk) (e:bool) (#[@@@erasable] a:squash e -> Type) (#[@@@erasable] b:squash (not e) -> Type) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#ar1:_) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#ar2:_) ([@@@erasable] p1:squash e -> parser k (a())) (v1:(squash e -> validate_with_action_t (p1()) inv1 disj1 l1 ar1)) ([@@@erasable] p2:squash (not e) -> parser k (b())) (v2:(squash (not e) -> validate_with_action_t (p2()) inv2 disj2 l2 ar2)) : validate_with_action_t (parse_ite e p1 p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false noextract inline_for_extraction val validate_nlist (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv disj l allow_reading) : validate_with_action_t (parse_nlist n p) inv disj l false noextract inline_for_extraction val validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv disj l allow_reading) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) noextract inline_for_extraction val validate_t_at_most (n:U32.t) (#nz: _) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#ar:_) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) noextract inline_for_extraction val validate_t_exact (n:U32.t) (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#ar:_) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv disj l false) inline_for_extraction noextract val validate_with_comment (c:string) (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) : validate_with_action_t p inv disj l allow_reading inline_for_extraction noextract val validate_weaken_inv_loc (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) ([@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) ([@@@erasable] disj':disjointness_pre { disj' `imp_disjointness` disj }) ([@@@erasable] l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l allow_reading) : Tot (validate_with_action_t p inv' disj' l' allow_reading) inline_for_extraction noextract val read_filter (#nz:_) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#[@@@erasable] p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) inline_for_extraction noextract val read_impos : leaf_reader (parse_impos())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "EverParse3d.Prelude.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked" ], "interface_file": false, "source_file": "EverParse3d.Actions.Base.fsti" }
[ { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: EverParse3d.Prelude.parser k t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none" ]
[]
false
false
false
false
true
let validator #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) =
validate_with_action_t p true_inv disjointness_trivial eloc_none true
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.lemma_feval_is_fas_nat
val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i]))
val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 127, "start_col": 0, "start_line": 126 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i]))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
h: FStar.Monotonic.HyperStack.mem -> f: Hacl.Impl.Poly1305.Fields.felem s -> FStar.Pervasives.Lemma (requires Hacl.Impl.Poly1305.Field32xN.felem_less h f (Prims.pow2 128)) (ensures forall (i: Prims.nat). i < Hacl.Impl.Poly1305.Fields.width s ==> (Hacl.Impl.Poly1305.Fields.feval h f).[ i ] == (Hacl.Impl.Poly1305.Fields.fas_nat h f).[ i ])
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.lemma_feval_is_fas_nat", "Hacl.Impl.Poly1305.Fields.width", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_feval_is_fas_nat #s h f =
F32xN.lemma_feval_is_fas_nat #(width s) h f
false
Spec.Hash.MD.fst
Spec.Hash.MD.max_input_size_len
val max_input_size_len (a: hash_alg{is_md a}) : Lemma (ensures FStar.Mul.(Some?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8)))
val max_input_size_len (a: hash_alg{is_md a}) : Lemma (ensures FStar.Mul.(Some?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8)))
let max_input_size_len (a: hash_alg{is_md a}): Lemma (ensures FStar.Mul.(Some ?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8))) = let open FStar.Mul in assert_norm (Some?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8))
{ "file_name": "specs/Spec.Hash.MD.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 22, "start_col": 0, "start_line": 18 }
module Spec.Hash.MD module S = FStar.Seq open Lib.IntTypes open Lib.ByteSequence open Spec.Hash.Definitions (** This module contains a Merkle-Damgard padding scheme for the MD hashes ONLY (md5, sha1, sha2) In Spec.Agile.Hash, the one-shot hash for MD hashes is defined pad, update_multi, finish. *) #push-options "--fuel 2 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Hash.MD.fst" }
[ { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "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": 0, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.Hash.Definitions.is_md a} -> FStar.Pervasives.Lemma (ensures Some?.v (Spec.Hash.Definitions.max_input_length a) * 8 + 8 = Prims.pow2 (Spec.Hash.Definitions.len_length a * 8))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.Hash.Definitions.is_md", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.pos", "Spec.Hash.Definitions.max_input_length", "Prims.pow2", "Spec.Hash.Definitions.len_length", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let max_input_size_len (a: hash_alg{is_md a}) : Lemma (ensures FStar.Mul.(Some?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8))) =
let open FStar.Mul in assert_norm (Some?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8))
false
Spec.Hash.MD.fst
Spec.Hash.MD.pad
val pad (a: md_alg) (total_len: nat{total_len `less_than_max_input_length` a}) : Tot (b: bytes{(S.length b + total_len) % block_length a = 0})
val pad (a: md_alg) (total_len: nat{total_len `less_than_max_input_length` a}) : Tot (b: bytes{(S.length b + total_len) % block_length a = 0})
let pad (a:md_alg) (total_len:nat{total_len `less_than_max_input_length` a}): Tot (b:bytes{(S.length b + total_len) % block_length a = 0}) = let open FStar.Mul in let firstbyte = S.create 1 (u8 0x80) in let zeros = S.create (pad0_length a total_len) (u8 0) in let total_len_bits = total_len * 8 in // Saves the need for high fuel + makes hint replayable. max_input_size_len a; let encodedlen : lbytes (len_length a) = match a with | MD5 -> Lib.ByteSequence.uint_to_bytes_le (secret (nat_to_len a (total_len * 8))) | _ -> Lib.ByteSequence.uint_to_bytes_be (secret (nat_to_len a (total_len * 8))) in S.(firstbyte @| zeros @| encodedlen)
{ "file_name": "specs/Spec.Hash.MD.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 43, "start_col": 0, "start_line": 29 }
module Spec.Hash.MD module S = FStar.Seq open Lib.IntTypes open Lib.ByteSequence open Spec.Hash.Definitions (** This module contains a Merkle-Damgard padding scheme for the MD hashes ONLY (md5, sha1, sha2) In Spec.Agile.Hash, the one-shot hash for MD hashes is defined pad, update_multi, finish. *) #push-options "--fuel 2 --ifuel 0" (* A useful lemma for all the operations that involve going from bytes to bits. *) let max_input_size_len (a: hash_alg{is_md a}): Lemma (ensures FStar.Mul.(Some ?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8))) = let open FStar.Mul in assert_norm (Some?.v (max_input_length a) * 8 + 8 = pow2 (len_length a * 8)) #pop-options (** Padding *) #set-options "--fuel 0 --ifuel 0 --z3rlimit 10"
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Hash.MD.fst" }
[ { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.md_alg -> total_len: Prims.nat{Spec.Hash.Definitions.less_than_max_input_length total_len a} -> b: Spec.Hash.Definitions.bytes {(FStar.Seq.Base.length b + total_len) % Spec.Hash.Definitions.block_length a = 0}
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.md_alg", "Prims.nat", "Prims.b2t", "Spec.Hash.Definitions.less_than_max_input_length", "FStar.Seq.Base.op_At_Bar", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Sequence.lseq", "Spec.Hash.Definitions.len_length", "Lib.ByteSequence.uint_to_bytes_le", "Spec.Hash.Definitions.len_int_type", "Lib.IntTypes.secret", "Spec.Hash.Definitions.nat_to_len", "FStar.Mul.op_Star", "Spec.Hash.Definitions.hash_alg", "Lib.ByteSequence.uint_to_bytes_be", "Prims.unit", "Spec.Hash.MD.max_input_size_len", "Prims.int", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Spec.Hash.Definitions.pad0_length", "Lib.IntTypes.u8", "Spec.Hash.Definitions.bytes", "Prims.op_Equality", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Seq.Base.length", "Lib.IntTypes.uint8", "Spec.Hash.Definitions.block_length" ]
[]
false
false
false
false
false
let pad (a: md_alg) (total_len: nat{total_len `less_than_max_input_length` a}) : Tot (b: bytes{(S.length b + total_len) % block_length a = 0}) =
let open FStar.Mul in let firstbyte = S.create 1 (u8 0x80) in let zeros = S.create (pad0_length a total_len) (u8 0) in let total_len_bits = total_len * 8 in max_input_size_len a; let encodedlen:lbytes (len_length a) = match a with | MD5 -> Lib.ByteSequence.uint_to_bytes_le (secret (nat_to_len a (total_len * 8))) | _ -> Lib.ByteSequence.uint_to_bytes_be (secret (nat_to_len a (total_len * 8))) in let open S in firstbyte @| zeros @| encodedlen
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.set_zero
val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0)
val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0)
let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 264, "start_col": 0, "start_line": 260 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
f: Hacl.Impl.Poly1305.Fields.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.set_zero", "Prims.unit" ]
[]
false
true
false
false
false
let set_zero #s f =
match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.create_felem
val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0)
val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0)
let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 141, "start_col": 0, "start_line": 137 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
s: Hacl.Impl.Poly1305.Fields.field_spec -> FStar.HyperStack.ST.StackInline (Hacl.Impl.Poly1305.Fields.felem s)
FStar.HyperStack.ST.StackInline
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Field32xN.create_felem", "Hacl.Impl.Poly1305.Field32xN.felem", "Hacl.Impl.Poly1305.Fields.felem" ]
[]
false
true
false
false
false
let create_felem s =
match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.reduce_felem
val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0])
val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0])
let reduce_felem #s f = match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 282, "start_col": 0, "start_line": 278 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0) let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f inline_for_extraction noextract val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0])
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
f: Hacl.Impl.Poly1305.Fields.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.reduce_felem", "Prims.unit" ]
[]
false
true
false
false
false
let reduce_felem #s f =
match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.load_felem_le
val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b)))
val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b)))
let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 161, "start_col": 0, "start_line": 157 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b)))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
f: Hacl.Impl.Poly1305.Fields.felem s -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Poly1305.Field32xN.load_felem_le", "Prims.unit" ]
[]
false
true
false
false
false
let load_felem_le #s f b =
match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.uints64_from_felem_le
val uints64_from_felem_le: #s:field_spec -> f:felem s -> Stack (uint64 & uint64) (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1)) (ensures fun h0 (lo, hi) h1 -> h0 == h1 /\ v hi * pow2 64 + v lo == (fas_nat h0 f).[0] % pow2 128)
val uints64_from_felem_le: #s:field_spec -> f:felem s -> Stack (uint64 & uint64) (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1)) (ensures fun h0 (lo, hi) h1 -> h0 == h1 /\ v hi * pow2 64 + v lo == (fas_nat h0 f).[0] % pow2 128)
let uints64_from_felem_le #s f = match s with | M32 -> F32xN.uints64_from_felem_le #1 f | M128 -> F32xN.uints64_from_felem_le #2 f | M256 -> F32xN.uints64_from_felem_le #4 f
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 418, "start_col": 0, "start_line": 414 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0) let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f inline_for_extraction noextract val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0]) let reduce_felem #s f = match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f inline_for_extraction noextract val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0))) let load_precompute_r #s p r0 r1 = match s with | M32 -> F32xN.load_precompute_r #1 p r0 r1 | M128 -> F32xN.load_precompute_r #2 p r0 r1 | M256 -> F32xN.load_precompute_r #4 p r0 r1 inline_for_extraction noextract val fadd_mul_r: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ F32xN.fmul_precomp_r_pre #(width s) h precomp /\ felem_fits h out (2, 2, 2, 2, 2) /\ felem_fits h f1 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (Vec.fadd (feval h0 out) (feval h0 f1)) (feval h0 (gsub precomp 0ul 5ul))) let fadd_mul_r #s out f1 precomp = match s with | M32 -> F32xN.fadd_mul_r #1 out f1 precomp | M128 -> F32xN.fadd_mul_r #2 out f1 precomp | M256 -> F32xN.fadd_mul_r #4 out f1 precomp inline_for_extraction noextract val fmul_rn: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ (let rn = gsub precomp 10ul 5ul in let rn_5 = gsub precomp 15ul 5ul in felem_fits h f1 (3, 3, 3, 3, 3) /\ felem_fits h rn (2, 2, 2, 2, 2) /\ felem_fits h rn_5 (10, 10, 10, 10, 10) /\ F32xN.as_tup5 #(width s) h rn_5 == F32xN.precomp_r5 (F32xN.as_tup5 h rn))) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (feval h0 f1) (feval h0 (gsub precomp 10ul 5ul))) let fmul_rn #s out f1 precomp = match s with | M32 -> F32xN.fmul_rn #1 out f1 precomp | M128 -> F32xN.fmul_rn #2 out f1 precomp | M256 -> F32xN.fmul_rn #4 out f1 precomp inline_for_extraction noextract val fmul_rn_normalize: #s:field_spec -> out:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h precomp /\ felem_fits h out (3, 3, 3, 3, 3) /\ F32xN.load_precompute_r_post #(width s) h precomp) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (feval h1 out).[0] == Vec.normalize_n #(width s) (feval h0 (gsub precomp 0ul 5ul)).[0] (feval h0 out)) let fmul_rn_normalize #s out precomp = match s with | M32 -> Field32xN_32.fmul_r1_normalize out precomp | M128 -> Field32xN_128.fmul_r2_normalize out precomp | M256 -> Field32xN_256.fmul_r4_normalize out precomp inline_for_extraction noextract val fadd: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ felem_fits h f1 (2, 2, 2, 2, 2) /\ felem_fits h f2 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (3, 3, 3, 3, 3) /\ feval h1 out == Vec.fadd (feval h0 f1) (feval h0 f2)) let fadd #s out f1 f2 = match s with | M32 -> F32xN.fadd #1 out f1 f2 | M128 -> F32xN.fadd #2 out f1 f2 | M256 -> F32xN.fadd #4 out f1 f2 inline_for_extraction noextract val uints64_from_felem_le: #s:field_spec -> f:felem s -> Stack (uint64 & uint64) (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1)) (ensures fun h0 (lo, hi) h1 -> h0 == h1 /\ v hi * pow2 64 + v lo == (fas_nat h0 f).[0] % pow2 128)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
f: Hacl.Impl.Poly1305.Fields.felem s -> FStar.HyperStack.ST.Stack (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.uints64_from_felem_le", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.uint64" ]
[]
false
true
false
false
false
let uints64_from_felem_le #s f =
match s with | M32 -> F32xN.uints64_from_felem_le #1 f | M128 -> F32xN.uints64_from_felem_le #2 f | M256 -> F32xN.uints64_from_felem_le #4 f
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.set_bit128
val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 246, "start_col": 0, "start_line": 242 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
f: Hacl.Impl.Poly1305.Fields.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.set_bit128", "Prims.unit" ]
[]
false
true
false
false
false
let set_bit128 #s f =
match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.set_bit
val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 225, "start_col": 0, "start_line": 221 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
f: Hacl.Impl.Poly1305.Fields.felem s -> i: Lib.IntTypes.size_t{Lib.IntTypes.size_v i <= 128} -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.size_v", "Hacl.Impl.Poly1305.Field32xN.set_bit", "Prims.unit" ]
[]
false
true
false
false
false
let set_bit #s f i =
match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.fadd
val fadd: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ felem_fits h f1 (2, 2, 2, 2, 2) /\ felem_fits h f2 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (3, 3, 3, 3, 3) /\ feval h1 out == Vec.fadd (feval h0 f1) (feval h0 f2))
val fadd: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ felem_fits h f1 (2, 2, 2, 2, 2) /\ felem_fits h f2 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (3, 3, 3, 3, 3) /\ feval h1 out == Vec.fadd (feval h0 f1) (feval h0 f2))
let fadd #s out f1 f2 = match s with | M32 -> F32xN.fadd #1 out f1 f2 | M128 -> F32xN.fadd #2 out f1 f2 | M256 -> F32xN.fadd #4 out f1 f2
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 401, "start_col": 0, "start_line": 397 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0) let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f inline_for_extraction noextract val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0]) let reduce_felem #s f = match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f inline_for_extraction noextract val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0))) let load_precompute_r #s p r0 r1 = match s with | M32 -> F32xN.load_precompute_r #1 p r0 r1 | M128 -> F32xN.load_precompute_r #2 p r0 r1 | M256 -> F32xN.load_precompute_r #4 p r0 r1 inline_for_extraction noextract val fadd_mul_r: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ F32xN.fmul_precomp_r_pre #(width s) h precomp /\ felem_fits h out (2, 2, 2, 2, 2) /\ felem_fits h f1 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (Vec.fadd (feval h0 out) (feval h0 f1)) (feval h0 (gsub precomp 0ul 5ul))) let fadd_mul_r #s out f1 precomp = match s with | M32 -> F32xN.fadd_mul_r #1 out f1 precomp | M128 -> F32xN.fadd_mul_r #2 out f1 precomp | M256 -> F32xN.fadd_mul_r #4 out f1 precomp inline_for_extraction noextract val fmul_rn: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ (let rn = gsub precomp 10ul 5ul in let rn_5 = gsub precomp 15ul 5ul in felem_fits h f1 (3, 3, 3, 3, 3) /\ felem_fits h rn (2, 2, 2, 2, 2) /\ felem_fits h rn_5 (10, 10, 10, 10, 10) /\ F32xN.as_tup5 #(width s) h rn_5 == F32xN.precomp_r5 (F32xN.as_tup5 h rn))) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (feval h0 f1) (feval h0 (gsub precomp 10ul 5ul))) let fmul_rn #s out f1 precomp = match s with | M32 -> F32xN.fmul_rn #1 out f1 precomp | M128 -> F32xN.fmul_rn #2 out f1 precomp | M256 -> F32xN.fmul_rn #4 out f1 precomp inline_for_extraction noextract val fmul_rn_normalize: #s:field_spec -> out:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h precomp /\ felem_fits h out (3, 3, 3, 3, 3) /\ F32xN.load_precompute_r_post #(width s) h precomp) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (feval h1 out).[0] == Vec.normalize_n #(width s) (feval h0 (gsub precomp 0ul 5ul)).[0] (feval h0 out)) let fmul_rn_normalize #s out precomp = match s with | M32 -> Field32xN_32.fmul_r1_normalize out precomp | M128 -> Field32xN_128.fmul_r2_normalize out precomp | M256 -> Field32xN_256.fmul_r4_normalize out precomp inline_for_extraction noextract val fadd: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ felem_fits h f1 (2, 2, 2, 2, 2) /\ felem_fits h f2 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (3, 3, 3, 3, 3) /\ feval h1 out == Vec.fadd (feval h0 f1) (feval h0 f2))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Impl.Poly1305.Fields.felem s -> f1: Hacl.Impl.Poly1305.Fields.felem s -> f2: Hacl.Impl.Poly1305.Fields.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Field32xN.fadd", "Prims.unit" ]
[]
false
true
false
false
false
let fadd #s out f1 f2 =
match s with | M32 -> F32xN.fadd #1 out f1 f2 | M128 -> F32xN.fadd #2 out f1 f2 | M256 -> F32xN.fadd #4 out f1 f2
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.load_felems_le
val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b))
val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b))
let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 181, "start_col": 0, "start_line": 177 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
f: Hacl.Impl.Poly1305.Fields.felem s -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Hacl.Impl.Poly1305.Fields.blocklen s) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Impl.Poly1305.Fields.blocklen", "Hacl.Impl.Poly1305.Field32xN.load_felems_le", "Prims.unit" ]
[]
false
true
false
false
false
let load_felems_le #s f b =
match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.load_acc
val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0])
val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0])
let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 202, "start_col": 0, "start_line": 198 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0])
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
acc: Hacl.Impl.Poly1305.Fields.felem s -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Hacl.Impl.Poly1305.Fields.blocklen s) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Impl.Poly1305.Fields.blocklen", "Hacl.Impl.Poly1305.Field32xN_32.load_acc1", "Prims.unit", "Hacl.Impl.Poly1305.Field32xN_128.load_acc2", "Hacl.Impl.Poly1305.Field32xN_256.load_acc4" ]
[]
false
true
false
false
false
let load_acc #s acc b =
match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.load_precompute_r
val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0)))
val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r #s p r0 r1 = match s with | M32 -> F32xN.load_precompute_r #1 p r0 r1 | M128 -> F32xN.load_precompute_r #2 p r0 r1 | M256 -> F32xN.load_precompute_r #4 p r0 r1
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 304, "start_col": 0, "start_line": 300 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0) let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f inline_for_extraction noextract val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0]) let reduce_felem #s f = match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f inline_for_extraction noextract val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0)))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
p: Hacl.Impl.Poly1305.Fields.precomp_r s -> r0: Lib.IntTypes.uint64 -> r1: Lib.IntTypes.uint64 -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.precomp_r", "Lib.IntTypes.uint64", "Hacl.Impl.Poly1305.Field32xN.load_precompute_r", "Prims.unit" ]
[]
false
true
false
false
false
let load_precompute_r #s p r0 r1 =
match s with | M32 -> F32xN.load_precompute_r #1 p r0 r1 | M128 -> F32xN.load_precompute_r #2 p r0 r1 | M256 -> F32xN.load_precompute_r #4 p r0 r1
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.fmul_rn
val fmul_rn: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ (let rn = gsub precomp 10ul 5ul in let rn_5 = gsub precomp 15ul 5ul in felem_fits h f1 (3, 3, 3, 3, 3) /\ felem_fits h rn (2, 2, 2, 2, 2) /\ felem_fits h rn_5 (10, 10, 10, 10, 10) /\ F32xN.as_tup5 #(width s) h rn_5 == F32xN.precomp_r5 (F32xN.as_tup5 h rn))) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (feval h0 f1) (feval h0 (gsub precomp 10ul 5ul)))
val fmul_rn: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ (let rn = gsub precomp 10ul 5ul in let rn_5 = gsub precomp 15ul 5ul in felem_fits h f1 (3, 3, 3, 3, 3) /\ felem_fits h rn (2, 2, 2, 2, 2) /\ felem_fits h rn_5 (10, 10, 10, 10, 10) /\ F32xN.as_tup5 #(width s) h rn_5 == F32xN.precomp_r5 (F32xN.as_tup5 h rn))) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (feval h0 f1) (feval h0 (gsub precomp 10ul 5ul)))
let fmul_rn #s out f1 precomp = match s with | M32 -> F32xN.fmul_rn #1 out f1 precomp | M128 -> F32xN.fmul_rn #2 out f1 precomp | M256 -> F32xN.fmul_rn #4 out f1 precomp
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 356, "start_col": 0, "start_line": 352 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0) let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f inline_for_extraction noextract val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0]) let reduce_felem #s f = match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f inline_for_extraction noextract val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0))) let load_precompute_r #s p r0 r1 = match s with | M32 -> F32xN.load_precompute_r #1 p r0 r1 | M128 -> F32xN.load_precompute_r #2 p r0 r1 | M256 -> F32xN.load_precompute_r #4 p r0 r1 inline_for_extraction noextract val fadd_mul_r: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ F32xN.fmul_precomp_r_pre #(width s) h precomp /\ felem_fits h out (2, 2, 2, 2, 2) /\ felem_fits h f1 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (Vec.fadd (feval h0 out) (feval h0 f1)) (feval h0 (gsub precomp 0ul 5ul))) let fadd_mul_r #s out f1 precomp = match s with | M32 -> F32xN.fadd_mul_r #1 out f1 precomp | M128 -> F32xN.fadd_mul_r #2 out f1 precomp | M256 -> F32xN.fadd_mul_r #4 out f1 precomp inline_for_extraction noextract val fmul_rn: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ (let rn = gsub precomp 10ul 5ul in let rn_5 = gsub precomp 15ul 5ul in felem_fits h f1 (3, 3, 3, 3, 3) /\ felem_fits h rn (2, 2, 2, 2, 2) /\ felem_fits h rn_5 (10, 10, 10, 10, 10) /\ F32xN.as_tup5 #(width s) h rn_5 == F32xN.precomp_r5 (F32xN.as_tup5 h rn))) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (feval h0 f1) (feval h0 (gsub precomp 10ul 5ul)))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Impl.Poly1305.Fields.felem s -> f1: Hacl.Impl.Poly1305.Fields.felem s -> precomp: Hacl.Impl.Poly1305.Fields.precomp_r s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Fields.precomp_r", "Hacl.Impl.Poly1305.Field32xN.fmul_rn", "Prims.unit" ]
[]
false
true
false
false
false
let fmul_rn #s out f1 precomp =
match s with | M32 -> F32xN.fmul_rn #1 out f1 precomp | M128 -> F32xN.fmul_rn #2 out f1 precomp | M256 -> F32xN.fmul_rn #4 out f1 precomp
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.fadd_mul_r
val fadd_mul_r: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ F32xN.fmul_precomp_r_pre #(width s) h precomp /\ felem_fits h out (2, 2, 2, 2, 2) /\ felem_fits h f1 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (Vec.fadd (feval h0 out) (feval h0 f1)) (feval h0 (gsub precomp 0ul 5ul)))
val fadd_mul_r: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ F32xN.fmul_precomp_r_pre #(width s) h precomp /\ felem_fits h out (2, 2, 2, 2, 2) /\ felem_fits h f1 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (Vec.fadd (feval h0 out) (feval h0 f1)) (feval h0 (gsub precomp 0ul 5ul)))
let fadd_mul_r #s out f1 precomp = match s with | M32 -> F32xN.fadd_mul_r #1 out f1 precomp | M128 -> F32xN.fadd_mul_r #2 out f1 precomp | M256 -> F32xN.fadd_mul_r #4 out f1 precomp
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 329, "start_col": 0, "start_line": 325 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0) let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f inline_for_extraction noextract val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0]) let reduce_felem #s f = match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f inline_for_extraction noextract val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0))) let load_precompute_r #s p r0 r1 = match s with | M32 -> F32xN.load_precompute_r #1 p r0 r1 | M128 -> F32xN.load_precompute_r #2 p r0 r1 | M256 -> F32xN.load_precompute_r #4 p r0 r1 inline_for_extraction noextract val fadd_mul_r: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ F32xN.fmul_precomp_r_pre #(width s) h precomp /\ felem_fits h out (2, 2, 2, 2, 2) /\ felem_fits h f1 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (Vec.fadd (feval h0 out) (feval h0 f1)) (feval h0 (gsub precomp 0ul 5ul)))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Impl.Poly1305.Fields.felem s -> f1: Hacl.Impl.Poly1305.Fields.felem s -> precomp: Hacl.Impl.Poly1305.Fields.precomp_r s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Fields.precomp_r", "Hacl.Impl.Poly1305.Field32xN.fadd_mul_r", "Prims.unit" ]
[]
false
true
false
false
false
let fadd_mul_r #s out f1 precomp =
match s with | M32 -> F32xN.fadd_mul_r #1 out f1 precomp | M128 -> F32xN.fadd_mul_r #2 out f1 precomp | M256 -> F32xN.fadd_mul_r #4 out f1 precomp
false
Hacl.Spec.Bignum.Definitions.fst
Hacl.Spec.Bignum.Definitions.bn_update_sub_eval
val bn_update_sub_eval: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (bn_v (update_sub a i bLen b) == bn_v a - bn_v (sub a i bLen) * pow2 (bits t * i) + bn_v b * pow2 (bits t * i))
val bn_update_sub_eval: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (bn_v (update_sub a i bLen b) == bn_v a - bn_v (sub a i bLen) * pow2 (bits t * i) + bn_v b * pow2 (bits t * i))
let bn_update_sub_eval #t #aLen #bLen a b i = let pbits = bits t in let a' = update_sub a i bLen b in let c = bn_v (sub a i bLen) * pow2 (bits t * i) in calc (==) { bn_v a' + c; (==) { bn_eval_split_i a' i } bn_v (slice a' 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { eq_intro (slice a 0 i) (slice a' 0 i) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; (==) { bn_eval_split_i (slice a' i aLen) bLen } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a' (i + bLen) aLen)) + c; (==) { eq_intro (slice a' (i + bLen) aLen) (slice a (i + bLen) aLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) {eq_intro (sub a' i bLen) b } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v b + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * i)) (bn_v b) (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * i) * (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; (==) { Math.Lemmas.paren_mul_right (pow2 (pbits * i)) (pow2 (pbits * bLen)) (bn_v (slice a (i + bLen) aLen)); Math.Lemmas.pow2_plus (pbits * i) (pbits * bLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen) + c; (==) { bn_eval_split_i (slice a 0 (i + bLen)) i } bn_v (slice a 0 (i + bLen)) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen); (==) { bn_eval_split_i a (i + bLen) } bn_v a + pow2 (pbits * i) * bn_v b; }
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 293, "start_col": 0, "start_line": 267 }
module Hacl.Spec.Bignum.Definitions open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val blocks0: x:size_nat -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks0 x m = if x = 0 then 1 else (x - 1) / m + 1 inline_for_extraction noextract let limb_t = t:inttype{t = U32 \/ t = U64} inline_for_extraction noextract let limb (t:limb_t) = uint_t t SEC let lbignum (t:limb_t) len = lseq (limb t) len val eval_: #t:limb_t -> len:size_nat -> s:lbignum t len -> i:nat{i <= len} -> nat let rec eval_ #t len s i = if i = 0 then 0 else eval_ #t len s (i - 1) + v s.[i - 1] * pow2 (bits t * (i - 1)) let bn_v (#t:limb_t) (#len:size_nat) (s:lbignum t len) = eval_ #t len s len /// /// Lemmas /// #push-options "--fuel 2" val bn_eval0: #t:limb_t -> #len:size_nat -> b:lbignum t len -> Lemma (eval_ len b 0 == 0) let bn_eval0 #t #len b = () val bn_eval1: #t:limb_t -> b:lbignum t 1 -> Lemma (bn_v b == v b.[0]) let bn_eval1 b = () val bn_eval_unfold_i: #t:limb_t -> #len:size_pos -> b:lbignum t len -> i:pos{i <= len} -> Lemma (eval_ len b i == eval_ len b (i - 1) + v b.[i - 1] * pow2 (bits t * (i - 1))) let bn_eval_unfold_i #t #len b i = () #pop-options val bn_eval_zeroes: #t:limb_t -> len:size_nat -> i:nat{i <= len} -> Lemma (eval_ len (create len (uint #t 0)) i == 0) let rec bn_eval_zeroes #t len i = let b = create len (uint #t 0) in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; bn_eval_zeroes #t len (i - 1) end val bn_eval_create1: #t:limb_t -> c:limb t -> Lemma (bn_v (create 1 c) == v c) let bn_eval_create1 #t c = bn_eval1 (create 1 c) val bn_eval_extensionality_j: #t:limb_t -> #len1:size_nat -> #len2:size_nat -> b1:lbignum t len1 -> b2:lbignum t len2 -> j:nat{j <= len1 /\ j <= len2} -> Lemma (requires sub b1 0 j == sub b2 0 j) (ensures eval_ len1 b1 j == eval_ len2 b2 j) (decreases j) let rec bn_eval_extensionality_j #t #len1 #len2 b1 b2 j = if j = 0 then begin bn_eval0 b1; bn_eval0 b2 end else begin bn_eval_unfold_i b1 j; bn_eval_unfold_i b2 j; let b1j = slice b1 0 j in let b2j = slice b2 0 j in let c1 = slice b1j 0 (j - 1) in let c2 = slice b2j 0 (j - 1) in eq_intro c1 c2; bn_eval_extensionality_j #t #len1 #len2 b1 b2 (j - 1); Seq.lemma_index_slice b1 0 j (j - 1); Seq.lemma_index_slice b2 0 j (j - 1); assert (v b1.[j - 1] == v b2.[j - 1]); () end val bn_eval_snoc: #t:limb_t -> #len:size_nat{len + 1 <= max_size_t} -> b:lbignum t len -> e:limb t -> Lemma (bn_v #t #(len + 1) (Seq.snoc b e) == bn_v b + v e * pow2 (bits t * len)) let bn_eval_snoc #t #len b e = let b1 = Seq.snoc b e in bn_eval_unfold_i #t #(len + 1) b1 (len + 1); bn_eval_extensionality_j #t #(len+1) #len b1 (slice #_ #(len+1) b1 0 len) len; eq_intro (sub #_ #(len + 1) b1 0 len) b val bn_eval_split_i_aux: p:nat -> a:nat -> b:nat -> c:nat -> i:nat -> Lemma (requires pow2 p * c == a - b) (ensures pow2 (p * (i + 1)) * c == pow2 (p * i) * a - pow2 (p * i) * b) let bn_eval_split_i_aux p a b c i = calc (==) { pow2 (p * (i + 1)) * c; (==) { Math.Lemmas.pow2_plus (p * i) p } pow2 (p * i) * pow2 p * c; (==) { Math.Lemmas.paren_mul_right (pow2 (p * i)) (pow2 p) c } pow2 (p * i) * (pow2 p * c); (==) { } pow2 (p * i) * (a - b); (==) { Math.Lemmas.distributivity_sub_right (pow2 (p * i)) a b } pow2 (p * i) * a - pow2 (p * i) * b; } #restart-solver val bn_eval_split_i: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (ensures bn_v b == bn_v (slice b 0 i) + pow2 (bits t * i) * bn_v (slice b i len)) (decreases (len - i)) // 20220513 JP: this proof broke somewhere in the calc, but even with --quake // 3/3 it goes through. Solver inconsistency? The restart solver above fixes it. let rec bn_eval_split_i #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 (slice b 0 i) else begin if len = i then bn_eval0 (slice b i len) else begin let b1 = slice b i len in bn_eval_split_i b1 1; bn_eval1 (slice b1 0 1); assert (bn_v b1 == v b1.[0] + pow2 pbits * bn_v (slice b1 1 (len - i))); Seq.lemma_index_slice b i len 0; assert (bn_v b1 == v b.[i] + pow2 pbits * bn_v (slice b (i + 1) len)); calc (==) { bn_v b; (==) { bn_eval_split_i b (i + 1) } bn_v (slice b 0 (i + 1)) + pow2 (pbits * (i + 1)) * bn_v (slice b (i + 1) len); (==) { bn_eval_split_i_aux pbits (bn_v b1) (v b.[i]) (bn_v (slice b (i + 1) len)) i } bn_v (slice b 0 (i + 1)) + pow2 (pbits * i) * bn_v b1 - pow2 (pbits * i) * v b.[i]; (==) { bn_eval_unfold_i (slice b 0 (i + 1)) (i + 1)} eval_ (i + 1) (slice b 0 (i + 1)) i + pow2 (pbits * i) * bn_v b1; (==) { bn_eval_extensionality_j (slice b 0 (i + 1)) (slice b 0 i) i } eval_ i (slice b 0 i) i + pow2 (pbits * i) * bn_v b1; }; () end end val bn_eval_inj: #t:limb_t -> len:size_nat -> b1:lbignum t len -> b2:lbignum t len -> Lemma (requires bn_v b1 == bn_v b2) (ensures equal b1 b2) (decreases len) let rec bn_eval_inj #t len b1 b2 = if len = 0 then () else begin bn_eval_split_i b1 1; bn_eval_split_i b2 1; bn_eval1 (slice b1 0 1); bn_eval1 (slice b2 0 1); bn_eval_inj (len - 1) (slice b1 1 len) (slice b2 1 len); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end val bn_eval_bound: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i <= len} -> Lemma (eval_ len b i < pow2 (bits t * i)) let rec bn_eval_bound #t #len b i = let pbits = bits t in if i = 0 then bn_eval0 b else begin bn_eval_unfold_i b i; assert (eval_ len b i == eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]); calc (<) { eval_ len b (i - 1) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (<) { bn_eval_bound #t #len b (i - 1) } pow2 (pbits * (i - 1)) + pow2 (pbits * (i - 1)) * v b.[i - 1]; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * (i - 1))) 1 (v b.[i - 1]) } pow2 (pbits * (i - 1)) * (1 + v b.[i - 1]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (pbits * (i - 1))) (1 + v b.[i - 1]) (pow2 pbits) } pow2 (pbits * (i - 1)) * pow2 pbits; (==) { Math.Lemmas.pow2_plus (pbits * (i - 1)) pbits } pow2 (pbits * i); }; assert (eval_ len b i < pow2 (pbits * i)) end val bn_eval_index: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> Lemma (v b.[i] == bn_v b / pow2 (bits t * i) % pow2 (bits t)) let bn_eval_index #t #len b i = let pbits = bits t in calc (==) { bn_v b / pow2 (pbits * i) % pow2 pbits; (==) { bn_eval_split_i #t #len b i } (bn_v (slice b 0 i) + pow2 (pbits * i) * bn_v (slice b i len)) / pow2 (pbits * i) % pow2 pbits; (==) { Math.Lemmas.division_addition_lemma (bn_v (slice b 0 i)) (pow2 (pbits * i)) (bn_v (slice b i len)) } (bn_v (slice b 0 i) / pow2 (pbits * i) + bn_v (slice b i len)) % pow2 pbits; (==) { bn_eval_bound (slice b 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice b 0 i)) (pow2 (pbits * i)) } bn_v (slice b i len) % pow2 pbits; (==) { bn_eval_split_i (slice b i len) 1 } (bn_v (slice b i (i + 1)) + pow2 pbits * bn_v (slice b (i + 1) len)) % pow2 pbits; (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice b i (i + 1))) (pow2 pbits) (bn_v (slice b (i + 1) len)) } bn_v (slice b i (i + 1)) % pow2 pbits; (==) { bn_eval1 (slice b i (i + 1)); Seq.lemma_index_slice b i (i + 1) 0 } v b.[i] % pow2 pbits; (==) { Math.Lemmas.modulo_lemma (v b.[i]) (pow2 pbits) } v b.[i]; }; assert (bn_v b / pow2 (pbits * i) % pow2 pbits == v b.[i]) val bn_eval_lt: #t:limb_t -> len:size_nat -> a:lbignum t len -> b:lbignum t len -> k:pos{k <= len} -> Lemma (requires v a.[k - 1] < v b.[k - 1]) (ensures eval_ len a k < eval_ len b k) let bn_eval_lt #t len a b k = let pbits = bits t in calc (==) { eval_ len b k - eval_ len a k; (==) { bn_eval_unfold_i b k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a k; (==) { bn_eval_unfold_i a k } eval_ len b (k - 1) + v b.[k - 1] * pow2 (pbits * (k - 1)) - eval_ len a (k - 1) - v a.[k - 1] * pow2 (pbits * (k - 1)); (==) { Math.Lemmas.distributivity_sub_left (v b.[k - 1]) (v a.[k - 1]) (pow2 (pbits * (k - 1))) } eval_ len b (k - 1) - eval_ len a (k - 1) + (v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)); }; bn_eval_bound a (k - 1); bn_eval_bound b (k - 1); assert (eval_ len b (k - 1) - eval_ len a (k - 1) > - pow2 (pbits * (k - 1))); assert ((v b.[k - 1] - v a.[k - 1]) * pow2 (pbits * (k - 1)) >= pow2 (pbits * (k - 1))) val bn_eval_update_sub: #t:limb_t -> len1:size_nat -> b1:lbignum t len1 -> len2:size_nat{len1 <= len2} -> Lemma (let b2 = create len2 (uint #t 0) in bn_v b1 == bn_v (update_sub b2 0 len1 b1)) let bn_eval_update_sub #t len1 b1 len2 = let b2 = create len2 (uint #t 0) in let b2 = update_sub b2 0 len1 b1 in bn_eval_split_i b2 len1; assert (bn_v b2 == bn_v b1 + pow2 (bits t * len1) * bn_v (slice b2 len1 len2)); let b_zeroes = create (len2 - len1) (uint #t 0) in eq_intro b_zeroes (slice b2 len1 len2); bn_eval_zeroes #t (len2 - len1) (len2 - len1) val bn_update_sub_eval: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (bn_v (update_sub a i bLen b) == bn_v a - bn_v (sub a i bLen) * pow2 (bits t * i) + bn_v b * pow2 (bits t * i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.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": false, "source_file": "Hacl.Spec.Bignum.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "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": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen -> i: Prims.nat{i + bLen <= aLen} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.update_sub a i bLen b) == Hacl.Spec.Bignum.Definitions.bn_v a - Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub a i bLen) * Prims.pow2 (Lib.IntTypes.bits t * i) + Hacl.Spec.Bignum.Definitions.bn_v b * Prims.pow2 (Lib.IntTypes.bits t * i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "Lib.Sequence.sub", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.squash", "Lib.Sequence.eq_intro", "FStar.Math.Lemmas.distributivity_add_right", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "Lib.IntTypes.bits", "Lib.Sequence.lseq", "Prims.l_and", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub" ]
[]
false
false
true
false
false
let bn_update_sub_eval #t #aLen #bLen a b i =
let pbits = bits t in let a' = update_sub a i bLen b in let c = bn_v (sub a i bLen) * pow2 (bits t * i) in calc ( == ) { bn_v a' + c; ( == ) { bn_eval_split_i a' i } bn_v (slice a' 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; ( == ) { eq_intro (slice a 0 i) (slice a' 0 i) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a' i aLen) + c; ( == ) { bn_eval_split_i (slice a' i aLen) bLen } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a' (i + bLen) aLen)) + c; ( == ) { eq_intro (slice a' (i + bLen) aLen) (slice a (i + bLen) aLen) } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v (sub a' i bLen) + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; ( == ) { eq_intro (sub a' i bLen) b } bn_v (slice a 0 i) + pow2 (pbits * i) * (bn_v b + pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; ( == ) { Math.Lemmas.distributivity_add_right (pow2 (pbits * i)) (bn_v b) (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * i) * (pow2 (pbits * bLen) * bn_v (slice a (i + bLen) aLen)) + c; ( == ) { (Math.Lemmas.paren_mul_right (pow2 (pbits * i)) (pow2 (pbits * bLen)) (bn_v (slice a (i + bLen) aLen)); Math.Lemmas.pow2_plus (pbits * i) (pbits * bLen)) } bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen) + c; ( == ) { bn_eval_split_i (slice a 0 (i + bLen)) i } bn_v (slice a 0 (i + bLen)) + pow2 (pbits * i) * bn_v b + pow2 (pbits * (i + bLen)) * bn_v (slice a (i + bLen) aLen); ( == ) { bn_eval_split_i a (i + bLen) } bn_v a + pow2 (pbits * i) * bn_v b; }
false
Hacl.Impl.Poly1305.Fields.fst
Hacl.Impl.Poly1305.Fields.fmul_rn_normalize
val fmul_rn_normalize: #s:field_spec -> out:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h precomp /\ felem_fits h out (3, 3, 3, 3, 3) /\ F32xN.load_precompute_r_post #(width s) h precomp) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (feval h1 out).[0] == Vec.normalize_n #(width s) (feval h0 (gsub precomp 0ul 5ul)).[0] (feval h0 out))
val fmul_rn_normalize: #s:field_spec -> out:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h precomp /\ felem_fits h out (3, 3, 3, 3, 3) /\ F32xN.load_precompute_r_post #(width s) h precomp) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (feval h1 out).[0] == Vec.normalize_n #(width s) (feval h0 (gsub precomp 0ul 5ul)).[0] (feval h0 out))
let fmul_rn_normalize #s out precomp = match s with | M32 -> Field32xN_32.fmul_r1_normalize out precomp | M128 -> Field32xN_128.fmul_r2_normalize out precomp | M256 -> Field32xN_256.fmul_r4_normalize out precomp
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 379, "start_col": 0, "start_line": 375 }
module Hacl.Impl.Poly1305.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Field32xN_32 open Hacl.Impl.Poly1305.Field32xN_128 open Hacl.Impl.Poly1305.Field32xN_256 open Hacl.Impl.Poly1305.Field32xN module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S = Spec.Poly1305 module Vec = Hacl.Spec.Poly1305.Vec module F32xN = Hacl.Impl.Poly1305.Field32xN #reset-options "--z3rlimit 50 --max_fuel 0 --max_fuel 0" noextract type field_spec = | M32 | M128 | M256 unfold noextract let width (s:field_spec) : Vec.lanes = match s with | M32 -> 1 | M128 -> 2 | M256 -> 4 unfold noextract let limb (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let limb_zero (s:field_spec) : limb s= match s with | M32 -> F32xN.zero 1 | M128 -> F32xN.zero 2 | M256 -> F32xN.zero 4 unfold noextract let wide (s:field_spec) = match s with | M32 -> F32xN.uint64xN 1 | M128 -> F32xN.uint64xN 2 | M256 -> F32xN.uint64xN 4 unfold noextract let nlimb (s:field_spec) : size_t = match s with | M32 -> 5ul | M128 -> 5ul | M256 -> 5ul unfold noextract let blocklen (s:field_spec) : r:size_t{0 < v r /\ v r == width s * S.size_block} = match s with | M32 -> 16ul | M128 -> 32ul | M256 -> 64ul unfold noextract let nelem (s:field_spec) : size_t = match s with | M32 -> 1ul | M128 -> 2ul | M256 -> 4ul unfold noextract let precomplen (s:field_spec) : size_t = match s with | M32 -> 20ul | M128 -> 20ul | M256 -> 20ul inline_for_extraction noextract type felem (s:field_spec) = lbuffer (limb s) (nlimb s) type felem_wide (s:field_spec) = lbuffer (wide s) (nlimb s) inline_for_extraction noextract type precomp_r (s:field_spec) = lbuffer (limb s) (precomplen s) noextract val felem_fits: #s:field_spec -> h:mem -> f:felem s -> m:F32xN.scale32_5 -> Type0 let felem_fits #s h f m = match s with | M32 -> F32xN.felem_fits #1 h f m | M128 -> F32xN.felem_fits #2 h f m | M256 -> F32xN.felem_fits #4 h f m noextract val fas_nat: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq nat (width s)) let fas_nat #s h e = match s with | M32 -> F32xN.fas_nat #1 h e | M128 -> F32xN.fas_nat #2 h e | M256 -> F32xN.fas_nat #4 h e noextract val feval: #s:field_spec -> h:mem -> e:felem s -> GTot (LSeq.lseq S.felem (width s)) let feval #s h e = match s with | M32 -> F32xN.feval #1 h e | M128 -> F32xN.feval #2 h e | M256 -> F32xN.feval #4 h e unfold noextract let op_String_Access #a #len = LSeq.index #a #len val lemma_feval_is_fas_nat: #s:field_spec -> h:mem -> f:felem s -> Lemma (requires F32xN.felem_less #(width s) h f (pow2 128)) (ensures (forall (i:nat). i < width s ==> (feval h f).[i] == (fas_nat h f).[i])) let lemma_feval_is_fas_nat #s h f = F32xN.lemma_feval_is_fas_nat #(width s) h f inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (limb_zero s)) /\ feval h1 f == LSeq.create (width s) 0) let create_felem s = match s with | M32 -> (F32xN.create_felem 1) <: felem s | M128 -> (F32xN.create_felem 2) <: felem s | M256 -> (F32xN.create_felem 4) <: felem s inline_for_extraction noextract val load_felem_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 16ul -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == LSeq.create (width s) (BSeq.nat_from_bytes_le (as_seq h0 b))) let load_felem_le #s f b = match s with | M32 -> F32xN.load_felem_le #1 f b | M128 -> F32xN.load_felem_le #2 f b | M256 -> F32xN.load_felem_le #4 f b inline_for_extraction noextract val load_felems_le: #s:field_spec -> f:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h f /\ live h b) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h1 f (pow2 128) /\ feval h1 f == Vec.load_elem #(width s) (as_seq h0 b)) let load_felems_le #s f b = match s with | M32 -> F32xN.load_felems_le #1 f b | M128 -> F32xN.load_felems_le #2 f b | M256 -> F32xN.load_felems_le #4 f b inline_for_extraction noextract val load_acc: #s:field_spec -> acc:felem s -> b:lbuffer uint8 (blocklen s) -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc #(width s) (as_seq h0 b) (feval h0 acc).[0]) let load_acc #s acc b = match s with | M32 -> Field32xN_32.load_acc1 acc b | M128 -> Field32xN_128.load_acc2 acc b | M256 -> Field32xN_256.load_acc4 acc b inline_for_extraction noextract val set_bit: #s:field_spec -> f:felem s -> i:size_t{size_v i <= 128} -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 (v i))) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (Math.Lemmas.pow2_le_compat 128 (v i); feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) let set_bit #s f i = match s with | M32 -> F32xN.set_bit #1 f i | M128 -> F32xN.set_bit #2 f i | M256 -> F32xN.set_bit #4 f i inline_for_extraction noextract val set_bit128: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (1, 1, 1, 1, 1) /\ F32xN.felem_less #(width s) h f (pow2 128)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f)) let set_bit128 #s f = match s with | M32 -> F32xN.set_bit128 #1 f | M128 -> F32xN.set_bit128 #2 f | M256 -> F32xN.set_bit128 #4 f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (0, 0, 0, 0, 0) /\ feval h1 f == LSeq.create (width s) 0) let set_zero #s f = match s with | M32 -> F32xN.set_zero #1 f | M128 -> F32xN.set_zero #2 f | M256 -> F32xN.set_zero #4 f inline_for_extraction noextract val reduce_felem: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f /\ felem_fits h f (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ felem_fits h1 f (1, 1, 1, 1, 1) /\ (fas_nat h1 f).[0] == (feval h0 f).[0]) let reduce_felem #s f = match s with | M32 -> F32xN.reduce_felem #1 f | M128 -> F32xN.reduce_felem #2 f | M256 -> F32xN.reduce_felem #4 f inline_for_extraction noextract val load_precompute_r: #s:field_spec -> p:precomp_r s -> r0:uint64 -> r1:uint64 -> Stack unit (requires fun h -> live h p) (ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\ F32xN.load_precompute_r_post #(width s) h1 p /\ (assert (uint_v r1 * pow2 64 + uint_v r0 < pow2 128); feval h1 (gsub p 0ul 5ul) == LSeq.create (width s) (uint_v r1 * pow2 64 + uint_v r0))) let load_precompute_r #s p r0 r1 = match s with | M32 -> F32xN.load_precompute_r #1 p r0 r1 | M128 -> F32xN.load_precompute_r #2 p r0 r1 | M256 -> F32xN.load_precompute_r #4 p r0 r1 inline_for_extraction noextract val fadd_mul_r: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ F32xN.fmul_precomp_r_pre #(width s) h precomp /\ felem_fits h out (2, 2, 2, 2, 2) /\ felem_fits h f1 (1, 1, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (Vec.fadd (feval h0 out) (feval h0 f1)) (feval h0 (gsub precomp 0ul 5ul))) let fadd_mul_r #s out f1 precomp = match s with | M32 -> F32xN.fadd_mul_r #1 out f1 precomp | M128 -> F32xN.fadd_mul_r #2 out f1 precomp | M256 -> F32xN.fadd_mul_r #4 out f1 precomp inline_for_extraction noextract val fmul_rn: #s:field_spec -> out:felem s -> f1:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h precomp /\ (let rn = gsub precomp 10ul 5ul in let rn_5 = gsub precomp 15ul 5ul in felem_fits h f1 (3, 3, 3, 3, 3) /\ felem_fits h rn (2, 2, 2, 2, 2) /\ felem_fits h rn_5 (10, 10, 10, 10, 10) /\ F32xN.as_tup5 #(width s) h rn_5 == F32xN.precomp_r5 (F32xN.as_tup5 h rn))) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (1, 2, 1, 1, 2) /\ feval h1 out == Vec.fmul (feval h0 f1) (feval h0 (gsub precomp 10ul 5ul))) let fmul_rn #s out f1 precomp = match s with | M32 -> F32xN.fmul_rn #1 out f1 precomp | M128 -> F32xN.fmul_rn #2 out f1 precomp | M256 -> F32xN.fmul_rn #4 out f1 precomp inline_for_extraction noextract val fmul_rn_normalize: #s:field_spec -> out:felem s -> precomp:precomp_r s -> Stack unit (requires fun h -> live h out /\ live h precomp /\ felem_fits h out (3, 3, 3, 3, 3) /\ F32xN.load_precompute_r_post #(width s) h precomp) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (feval h1 out).[0] == Vec.normalize_n #(width s) (feval h0 (gsub precomp 0ul 5ul)).[0] (feval h0 out))
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Impl.Poly1305.Field32xN_32.fst.checked", "Hacl.Impl.Poly1305.Field32xN_256.fst.checked", "Hacl.Impl.Poly1305.Field32xN_128.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": "F32xN" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN_32", "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": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Impl.Poly1305.Fields.felem s -> precomp: Hacl.Impl.Poly1305.Fields.precomp_r s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Fields.field_spec", "Hacl.Impl.Poly1305.Fields.felem", "Hacl.Impl.Poly1305.Fields.precomp_r", "Hacl.Impl.Poly1305.Field32xN_32.fmul_r1_normalize", "Prims.unit", "Hacl.Impl.Poly1305.Field32xN_128.fmul_r2_normalize", "Hacl.Impl.Poly1305.Field32xN_256.fmul_r4_normalize" ]
[]
false
true
false
false
false
let fmul_rn_normalize #s out precomp =
match s with | M32 -> Field32xN_32.fmul_r1_normalize out precomp | M128 -> Field32xN_128.fmul_r2_normalize out precomp | M256 -> Field32xN_256.fmul_r4_normalize out precomp
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.aux_write_exchange_allowed
val aux_write_exchange_allowed (w2: locations) (c1 c2: locations_with_values) (x: location) : pbool
val aux_write_exchange_allowed (w2: locations) (c1 c2: locations_with_values) (x: location) : pbool
let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write")
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 79, "start_col": 0, "start_line": 74 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
w2: Vale.Transformers.Locations.locations -> c1: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> c2: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> x: Vale.Transformers.Locations.location -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.Locations.locations", "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "Vale.Transformers.Locations.location", "Prims.list", "Vale.Def.PossiblyMonad.op_Bar_Bar_Dot", "Vale.Transformers.Locations.disjoint_location_from_locations", "Vale.Def.PossiblyMonad.op_Slash_Subtraction", "Prims.op_AmpAmp", "FStar.List.Tot.Base.mem", "Vale.Def.PossiblyMonad.pbool", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Vale.Transformers.InstructionReorder.locations_of_locations_with_values" ]
[]
false
false
false
true
false
let aux_write_exchange_allowed (w2: locations) (c1 c2: locations_with_values) (x: location) : pbool =
let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write")
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.write_exchange_allowed
val write_exchange_allowed (w1 w2: locations) (c1 c2: locations_with_values) : pbool
val write_exchange_allowed (w1 w2: locations) (c1 c2: locations_with_values) : pbool
let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 87, "start_col": 0, "start_line": 81 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write")
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
w1: Vale.Transformers.Locations.locations -> w2: Vale.Transformers.Locations.locations -> c1: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> c2: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.Locations.locations", "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "Vale.Def.PossiblyMonad.op_Amp_Amp_Dot", "Vale.Transformers.InstructionReorder.write_same_constants", "Vale.Def.PossiblyMonad.for_all", "Vale.Transformers.Locations.location", "Vale.Transformers.InstructionReorder.aux_write_exchange_allowed", "Vale.Def.PossiblyMonad.pbool" ]
[]
false
false
false
true
false
let write_exchange_allowed (w1 w2: locations) (c1 c2: locations_with_values) : pbool =
write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. for_all (aux_write_exchange_allowed w1 c2 c1) w2
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.rw_exchange_allowed
val rw_exchange_allowed (rw1 rw2: rw_set) : pbool
val rw_exchange_allowed (rw1 rw2: rw_set) : pbool
let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ")
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 94, "start_col": 0, "start_line": 89 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set -> rw2: Vale.Transformers.BoundedInstructionEffects.rw_set -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.BoundedInstructionEffects.rw_set", "Vale.Transformers.Locations.locations", "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "Vale.Def.PossiblyMonad.op_Amp_Amp_Dot", "Vale.Def.PossiblyMonad.op_Slash_Plus_Less", "Vale.Transformers.Locations.disjoint_locations", "Vale.Transformers.InstructionReorder.write_exchange_allowed", "Vale.Def.PossiblyMonad.pbool", "FStar.Pervasives.Native.tuple3", "Prims.list", "Vale.Transformers.Locations.location", "FStar.Pervasives.Native.Mktuple3", "Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads", "Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes", "Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes" ]
[]
false
false
false
true
false
let rw_exchange_allowed (rw1 rw2: rw_set) : pbool =
let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ")
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.ins_exchange_allowed
val ins_exchange_allowed (i1 i2: ins) : pbool
val ins_exchange_allowed (i1 i2: ins) : pbool
let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc)
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 85, "end_line": 103, "start_col": 0, "start_line": 96 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ")
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
i1: Vale.X64.Machine_Semantics_s.ins -> i2: Vale.X64.Machine_Semantics_s.ins -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.Def.PossiblyMonad.op_Slash_Plus_Greater", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.Transformers.InstructionReorder.rw_exchange_allowed", "Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins", "Vale.Def.PossiblyMonad.ffalse", "Vale.Def.PossiblyMonad.pbool", "Vale.X64.Instruction_s.normal", "Prims.string", "Prims.op_Hat", "Vale.X64.Print_s.print_ins", "Vale.X64.Print_s.gcc" ]
[]
false
false
false
true
false
let ins_exchange_allowed (i1 i2: ins) : pbool =
(match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange") /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc)
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.equiv_states_ext
val equiv_states_ext (s1 s2: machine_state) : GTot Type0
val equiv_states_ext (s1 s2: machine_state) : GTot Type0
let equiv_states_ext (s1 s2 : machine_state) : GTot Type0 = let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2)
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 155, "start_col": 0, "start_line": 149 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same. let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint) (** Same as [equiv_states] but uses extensionality to "think harder";
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Vale.X64.Machine_Semantics_s.machine_state", "Prims.l_and", "FStar.FunctionalExtensionality.feq", "Vale.X64.Machine_s.reg", "Vale.X64.Machine_s.t_reg", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs", "Prims.eq2", "Vale.Arch.Heap.heap_impl", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "FStar.Map.equal", "Prims.int", "Vale.Def.Types_s.nat8", "Vale.X64.Machine_Semantics_s.__proj__Machine_stack__item__stack_mem", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack", "Vale.Arch.HeapTypes_s.taint", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint", "Vale.Transformers.InstructionReorder.equiv_states" ]
[]
false
false
false
false
true
let equiv_states_ext (s1 s2: machine_state) : GTot Type0 =
let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2)
false
Hacl.Impl.Frodo.KEM.fst
Hacl.Impl.Frodo.KEM.clear_words_u8
val clear_words_u8: #len:size_t -> b:lbytes len -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1)
val clear_words_u8: #len:size_t -> b:lbytes len -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1)
let clear_words_u8 #len b = memzero #uint8 b len
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 39, "start_col": 0, "start_line": 38 }
module Hacl.Impl.Frodo.KEM open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.Memzero0 open Hacl.Impl.Matrix #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val clear_matrix: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> Stack unit (requires fun h -> live h m) (ensures fun h0 _ h1 -> modifies1 m h0 h1) let clear_matrix #n1 #n2 m = memzero #uint16 m (n1 *! n2) inline_for_extraction noextract val clear_words_u8: #len:size_t -> b:lbytes len -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.Memzero0", "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": "LowStar.Buffer", "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.Frodo", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
b: Hacl.Impl.Matrix.lbytes len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Hacl.Impl.Matrix.lbytes", "Lib.Memzero0.memzero", "Lib.IntTypes.uint8", "Prims.unit" ]
[]
false
true
false
false
false
let clear_words_u8 #len b =
memzero #uint8 b len
false
Hacl.Impl.Frodo.KEM.fst
Hacl.Impl.Frodo.KEM.clear_matrix
val clear_matrix: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> Stack unit (requires fun h -> live h m) (ensures fun h0 _ h1 -> modifies1 m h0 h1)
val clear_matrix: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> Stack unit (requires fun h -> live h m) (ensures fun h0 _ h1 -> modifies1 m h0 h1)
let clear_matrix #n1 #n2 m = memzero #uint16 m (n1 *! n2)
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 27, "start_col": 0, "start_line": 26 }
module Hacl.Impl.Frodo.KEM open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.Memzero0 open Hacl.Impl.Matrix #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val clear_matrix: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> Stack unit (requires fun h -> live h m) (ensures fun h0 _ h1 -> modifies1 m h0 h1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.Memzero0", "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": "LowStar.Buffer", "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.Frodo", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
m: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "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", "Hacl.Impl.Matrix.matrix_t", "Lib.Memzero0.memzero", "Lib.IntTypes.uint16", "Lib.IntTypes.op_Star_Bang", "Prims.unit" ]
[]
false
true
false
false
false
let clear_matrix #n1 #n2 m =
memzero #uint16 m (n1 *! n2)
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.equiv_states_or_both_not_ok
val equiv_states_or_both_not_ok : s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state -> Prims.logical
let equiv_states_or_both_not_ok (s1 s2:machine_state) = (equiv_states s1 s2) \/ ((not s1.ms_ok) /\ (not s2.ms_ok))
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 163, "start_col": 0, "start_line": 161 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same. let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint) (** Same as [equiv_states] but uses extensionality to "think harder"; useful at lower-level details of the proof. *) let equiv_states_ext (s1 s2 : machine_state) : GTot Type0 = let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2) (** A weaker version of [equiv_states] that makes all non-ok states equivalent. Since non-ok states indicate something "gone-wrong" in execution, we can safely say that the rest of the state is
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.machine_state", "Prims.l_or", "Vale.Transformers.InstructionReorder.equiv_states", "Prims.l_and", "Prims.b2t", "Prims.op_Negation", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Prims.logical" ]
[]
false
false
false
true
true
let equiv_states_or_both_not_ok (s1 s2: machine_state) =
(equiv_states s1 s2) \/ ((not s1.ms_ok) /\ (not s2.ms_ok))
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.proof_run
val proof_run (s: machine_state) (f: st unit) : machine_state
val proof_run (s: machine_state) (f: st unit) : machine_state
let proof_run (s:machine_state) (f:st unit) : machine_state = let (), s1 = f s in { s1 with ms_ok = s1.ms_ok && s.ms_ok }
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 195, "start_col": 0, "start_line": 193 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same. let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint) (** Same as [equiv_states] but uses extensionality to "think harder"; useful at lower-level details of the proof. *) let equiv_states_ext (s1 s2 : machine_state) : GTot Type0 = let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2) (** A weaker version of [equiv_states] that makes all non-ok states equivalent. Since non-ok states indicate something "gone-wrong" in execution, we can safely say that the rest of the state is irrelevant. *) let equiv_states_or_both_not_ok (s1 s2:machine_state) = (equiv_states s1 s2) \/ ((not s1.ms_ok) /\ (not s2.ms_ok)) (** Convenience wrapper around [equiv_states] *) unfold let equiv_ostates (s1 s2 : option machine_state) : GTot Type0 = (Some? s1 = Some? s2) /\ (Some? s1 ==> (equiv_states (Some?.v s1) (Some?.v s2))) (** An [option state] is said to be erroring if it is either [None] or if it is [Some] but is not ok. *) unfold let erroring_option_state (s:option machine_state) = match s with | None -> true | Some s -> not (s.ms_ok) (** [equiv_option_states s1 s2] means that [s1] and [s2] are equivalent [option machine_state]s iff both have same erroring behavior and if they are non-erroring, they are [equiv_states]. *) unfold let equiv_option_states (s1 s2:option machine_state) = (erroring_option_state s1 == erroring_option_state s2) /\ (not (erroring_option_state s1) ==> equiv_states (Some?.v s1) (Some?.v s2)) /// If evaluation starts from a set of equivalent states, and the /// exact same thing is evaluated, then the final states are still /// equivalent.
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s: Vale.X64.Machine_Semantics_s.machine_state -> f: Vale.X64.Machine_Semantics_s.st Prims.unit -> Vale.X64.Machine_Semantics_s.machine_state
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.st", "Prims.unit", "Vale.X64.Machine_Semantics_s.Mkmachine_state", "Prims.op_AmpAmp", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let proof_run (s: machine_state) (f: st unit) : machine_state =
let (), s1 = f s in { s1 with ms_ok = s1.ms_ok && s.ms_ok }
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.write_same_constants
val write_same_constants (c1 c2: locations_with_values) : pbool
val write_same_constants (c1 c2: locations_with_values) : pbool
let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 72, "start_col": 0, "start_line": 65 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed.
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
c1: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> c2: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "Vale.Def.PossiblyMonad.for_all", "Vale.Transformers.BoundedInstructionEffects.location_with_value", "Vale.Transformers.Locations.location_eq", "Vale.Transformers.Locations.location_val_eqt", "Vale.Def.PossiblyMonad.op_Slash_Subtraction", "Prims.op_Equality", "Prims.bool", "Vale.Def.PossiblyMonad.pbool" ]
[]
false
false
false
true
false
let write_same_constants (c1 c2: locations_with_values) : pbool =
for_all (fun (x1: location_with_value) -> for_all (fun (x2: location_with_value) -> let (| l1 , v1 |) = x1 in let (| l2 , v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants") c2) c1
false
Hacl.Test.ECDSA.fst
Hacl.Test.ECDSA.vec8
val vec8 : Type0
let vec8 = L.lbuffer UInt8.t
{ "file_name": "code/tests/Hacl.Test.ECDSA.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 74, "start_col": 0, "start_line": 74 }
module Hacl.Test.ECDSA open FStar.HyperStack.ST open Test.Lowstarize open Lib.IntTypes open Hacl.P256 open Spec.ECDSA.Test.Vectors module L = Test.Lowstarize module B = LowStar.Buffer #set-options "--fuel 0 --ifuel 0 --z3rlimit 100" noextract let sigver_vectors256_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_256 noextract let sigver_vectors384_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_384 noextract let sigver_vectors512_tmp = List.Tot.map (fun x -> h x.msg, h x.qx, h x.qy, h x.r, h x.s, x.result) sigver_vectors_sha2_512 noextract let siggen_vectors256_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_256 noextract let siggen_vectors384_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_384 noextract let siggen_vectors512_tmp = List.Tot.map (fun x -> h x.msg', h x.d, h x.qx', h x.qy', h x.k, h x.r', h x.s') siggen_vectors_sha2_512 %splice[sigver_vectors256_low] (lowstarize_toplevel "sigver_vectors256_tmp" "sigver_vectors256_low") %splice[sigver_vectors384_low] (lowstarize_toplevel "sigver_vectors384_tmp" "sigver_vectors384_low") %splice[sigver_vectors512_low] (lowstarize_toplevel "sigver_vectors512_tmp" "sigver_vectors512_low") %splice[siggen_vectors256_low] (lowstarize_toplevel "siggen_vectors256_tmp" "siggen_vectors256_low") %splice[siggen_vectors384_low] (lowstarize_toplevel "siggen_vectors384_tmp" "siggen_vectors384_low") %splice[siggen_vectors512_low] (lowstarize_toplevel "siggen_vectors512_tmp" "siggen_vectors512_low") // Cheap alternative to friend Lib.IntTypes needed because Test.Lowstarize uses UInt8.t assume val declassify_uint8: squash (uint8 == UInt8.t)
{ "checked_file": "/", "dependencies": [ "Test.Lowstarize.fst.checked", "Spec.P256.fst.checked", "Spec.ECDSA.Test.Vectors.fst.checked", "prims.fst.checked", "LowStar.Printf.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.P256.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "C.String.fsti.checked", "C.Loops.fst.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.ECDSA.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Test.Lowstarize", "short_module": "L" }, { "abbrev": false, "full_module": "Spec.ECDSA.Test.Vectors", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Test.Lowstarize", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Test.Lowstarize.lbuffer", "FStar.UInt8.t" ]
[]
false
false
false
true
true
let vec8 =
L.lbuffer UInt8.t
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.locations_of_locations_with_values
val locations_of_locations_with_values (lv: locations_with_values) : locations
val locations_of_locations_with_values (lv: locations_with_values) : locations
let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 59, "start_col": 0, "start_line": 55 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
lv: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> Vale.Transformers.Locations.locations
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "Prims.Nil", "Vale.Transformers.Locations.location", "Vale.Transformers.Locations.location_eq", "Vale.Transformers.Locations.location_val_eqt", "Prims.list", "Vale.Transformers.BoundedInstructionEffects.location_with_value", "Prims.Cons", "Vale.Transformers.InstructionReorder.locations_of_locations_with_values", "Vale.Transformers.Locations.locations" ]
[ "recursion" ]
false
false
false
true
false
let rec locations_of_locations_with_values (lv: locations_with_values) : locations =
match lv with | [] -> [] | (| l , v |) :: lv -> l :: locations_of_locations_with_values lv
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.lemma_write_same_constants_symmetric
val lemma_write_same_constants_symmetric (c1 c2: locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1)))
val lemma_write_same_constants_symmetric (c1 c2: locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1)))
let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 117, "start_col": 0, "start_line": 105 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
c1: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> c2: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> FStar.Pervasives.Lemma (ensures !!(Vale.Transformers.InstructionReorder.write_same_constants c1 c2) = !!(Vale.Transformers.InstructionReorder.write_same_constants c2 c1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "Vale.Transformers.BoundedInstructionEffects.location_with_value", "Vale.Transformers.InstructionReorder.lemma_write_same_constants_symmetric", "Prims.Nil", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "Vale.Def.PossiblyMonad.op_Bang_Bang", "Vale.Transformers.InstructionReorder.write_same_constants", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_write_same_constants_symmetric (c1 c2: locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) =
match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.equiv_ostates
val equiv_ostates (s1 s2: option machine_state) : GTot Type0
val equiv_ostates (s1 s2: option machine_state) : GTot Type0
let equiv_ostates (s1 s2 : option machine_state) : GTot Type0 = (Some? s1 = Some? s2) /\ (Some? s1 ==> (equiv_states (Some?.v s1) (Some?.v s2)))
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 170, "start_col": 0, "start_line": 167 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same. let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint) (** Same as [equiv_states] but uses extensionality to "think harder"; useful at lower-level details of the proof. *) let equiv_states_ext (s1 s2 : machine_state) : GTot Type0 = let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2) (** A weaker version of [equiv_states] that makes all non-ok states equivalent. Since non-ok states indicate something "gone-wrong" in execution, we can safely say that the rest of the state is irrelevant. *) let equiv_states_or_both_not_ok (s1 s2:machine_state) = (equiv_states s1 s2) \/ ((not s1.ms_ok) /\ (not s2.ms_ok)) (** Convenience wrapper around [equiv_states] *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s1: FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state -> s2: FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "FStar.Pervasives.Native.uu___is_Some", "Prims.l_imp", "Vale.Transformers.InstructionReorder.equiv_states", "FStar.Pervasives.Native.__proj__Some__item__v" ]
[]
false
false
false
false
true
let equiv_ostates (s1 s2: option machine_state) : GTot Type0 =
(Some? s1 = Some? s2) /\ (Some? s1 ==> (equiv_states (Some?.v s1) (Some?.v s2)))
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.lemma_write_exchange_allowed_symmetric
val lemma_write_exchange_allowed_symmetric (w1 w2: locations) (c1 c2: locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1)))
val lemma_write_exchange_allowed_symmetric (w1 w2: locations) (c1 c2: locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1)))
let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 122, "start_col": 0, "start_line": 119 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
w1: Vale.Transformers.Locations.locations -> w2: Vale.Transformers.Locations.locations -> c1: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> c2: Vale.Transformers.BoundedInstructionEffects.locations_with_values -> FStar.Pervasives.Lemma (ensures !!(Vale.Transformers.InstructionReorder.write_exchange_allowed w1 w2 c1 c2) = !!(Vale.Transformers.InstructionReorder.write_exchange_allowed w2 w1 c2 c1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Transformers.Locations.locations", "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "Vale.Transformers.InstructionReorder.lemma_write_same_constants_symmetric", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "Vale.Def.PossiblyMonad.op_Bang_Bang", "Vale.Transformers.InstructionReorder.write_exchange_allowed", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_write_exchange_allowed_symmetric (w1 w2: locations) (c1 c2: locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) =
lemma_write_same_constants_symmetric c1 c2
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.equiv_states
val equiv_states (s1 s2: machine_state) : GTot Type0
val equiv_states (s1 s2: machine_state) : GTot Type0
let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint)
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 145, "start_col": 0, "start_line": 138 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same.
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Vale.X64.Machine_Semantics_s.machine_state", "Prims.l_and", "Prims.eq2", "Prims.bool", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Vale.X64.Machine_Semantics_s.regs_t", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs", "Prims.b2t", "Prims.op_Equality", "Vale.X64.Machine_Semantics_s.flag_val_t", "Vale.X64.Machine_Semantics_s.cf", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags", "Vale.X64.Machine_Semantics_s.overflow", "Vale.Arch.Heap.heap_impl", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Machine_Semantics_s.machine_stack", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint" ]
[]
false
false
false
false
true
let equiv_states (s1 s2: machine_state) : GTot Type0 =
(s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint)
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.filt_state
val filt_state : s: Vale.X64.Machine_Semantics_s.machine_state -> Vale.X64.Machine_Semantics_s.machine_state
let filt_state (s:machine_state) = { s with ms_trace = [] }
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 419, "start_col": 0, "start_line": 417 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same. let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint) (** Same as [equiv_states] but uses extensionality to "think harder"; useful at lower-level details of the proof. *) let equiv_states_ext (s1 s2 : machine_state) : GTot Type0 = let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2) (** A weaker version of [equiv_states] that makes all non-ok states equivalent. Since non-ok states indicate something "gone-wrong" in execution, we can safely say that the rest of the state is irrelevant. *) let equiv_states_or_both_not_ok (s1 s2:machine_state) = (equiv_states s1 s2) \/ ((not s1.ms_ok) /\ (not s2.ms_ok)) (** Convenience wrapper around [equiv_states] *) unfold let equiv_ostates (s1 s2 : option machine_state) : GTot Type0 = (Some? s1 = Some? s2) /\ (Some? s1 ==> (equiv_states (Some?.v s1) (Some?.v s2))) (** An [option state] is said to be erroring if it is either [None] or if it is [Some] but is not ok. *) unfold let erroring_option_state (s:option machine_state) = match s with | None -> true | Some s -> not (s.ms_ok) (** [equiv_option_states s1 s2] means that [s1] and [s2] are equivalent [option machine_state]s iff both have same erroring behavior and if they are non-erroring, they are [equiv_states]. *) unfold let equiv_option_states (s1 s2:option machine_state) = (erroring_option_state s1 == erroring_option_state s2) /\ (not (erroring_option_state s1) ==> equiv_states (Some?.v s1) (Some?.v s2)) /// If evaluation starts from a set of equivalent states, and the /// exact same thing is evaluated, then the final states are still /// equivalent. unfold let proof_run (s:machine_state) (f:st unit) : machine_state = let (), s1 = f s in { s1 with ms_ok = s1.ms_ok && s.ms_ok } let rec lemma_instr_apply_eval_args_equiv_states (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( (instr_apply_eval_args outs args f oprs s1) == (instr_apply_eval_args outs args f oprs s2))) = match args with | [] -> () | i :: args -> let (v, oprs) : option (instr_val_t i) & _ = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_instr_apply_eval_args_equiv_states outs args (f v) oprs s1 s2 #push-options "--z3rlimit 10" let rec lemma_instr_apply_eval_inouts_equiv_states (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( (instr_apply_eval_inouts outs inouts args f oprs s1) == (instr_apply_eval_inouts outs inouts args f oprs s2))) = match inouts with | [] -> lemma_instr_apply_eval_args_equiv_states outs args f oprs s1 s2 | (Out, i) :: inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_instr_apply_eval_inouts_equiv_states outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> let (v, oprs) : option (instr_val_t i) & _ = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_instr_apply_eval_inouts_equiv_states outs inouts args (f v) oprs s1 s2 #pop-options #push-options "--z3rlimit 10 --max_fuel 1 --max_ifuel 0" let lemma_instr_write_output_implicit_equiv_states (i:instr_operand_implicit) (v:instr_val_t (IOpIm i)) (s_orig1 s1 s_orig2 s2:machine_state) : Lemma (requires ( (equiv_states s_orig1 s_orig2) /\ (equiv_states s1 s2))) (ensures ( (equiv_states (instr_write_output_implicit i v s_orig1 s1) (instr_write_output_implicit i v s_orig2 s2)))) = let snew1, snew2 = (instr_write_output_implicit i v s_orig1 s1), (instr_write_output_implicit i v s_orig2 s2) in assert (equiv_states_ext snew1 snew2) (* OBSERVE *) let lemma_instr_write_output_explicit_equiv_states (i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i) (s_orig1 s1 s_orig2 s2:machine_state) : Lemma (requires ( (equiv_states s_orig1 s_orig2) /\ (equiv_states s1 s2))) (ensures ( (equiv_states (instr_write_output_explicit i v o s_orig1 s1) (instr_write_output_explicit i v o s_orig2 s2)))) = let snew1, snew2 = (instr_write_output_explicit i v o s_orig1 s1), (instr_write_output_explicit i v o s_orig2 s2) in assert (equiv_states_ext snew1 snew2) (* OBSERVE *) #pop-options let rec lemma_instr_write_outputs_equiv_states (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig1 s1:machine_state) (s_orig2 s2:machine_state) : Lemma (requires ( (equiv_states s_orig1 s_orig2) /\ (equiv_states s1 s2))) (ensures ( (equiv_states (instr_write_outputs outs args vs oprs s_orig1 s1) (instr_write_outputs outs args vs oprs s_orig2 s2)))) = match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in lemma_instr_write_output_explicit_equiv_states i v (fst oprs) s_orig1 s1 s_orig2 s2; let s1 = instr_write_output_explicit i v (fst oprs) s_orig1 s1 in let s2 = instr_write_output_explicit i v (fst oprs) s_orig2 s2 in lemma_instr_write_outputs_equiv_states outs args vs (snd oprs) s_orig1 s1 s_orig2 s2 | IOpIm i -> lemma_instr_write_output_implicit_equiv_states i v s_orig1 s1 s_orig2 s2; let s1 = instr_write_output_implicit i v s_orig1 s1 in let s2 = instr_write_output_implicit i v s_orig2 s2 in lemma_instr_write_outputs_equiv_states outs args vs (coerce oprs) s_orig1 s1 s_orig2 s2 ) let lemma_eval_instr_equiv_states (it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it) (s1 s2:machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( equiv_ostates (eval_instr it oprs ann s1) (eval_instr it oprs ann s2))) = let InstrTypeRecord #outs #args #havoc_flags' i = it in let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in lemma_instr_apply_eval_inouts_equiv_states outs outs args (instr_eval i) oprs s1 s2; assert (vs1 == vs2); let s1_new = match havoc_flags' with | HavocFlags -> {s1 with ms_flags = havoc_flags} | PreserveFlags -> s1 in let s2_new = match havoc_flags' with | HavocFlags -> {s2 with ms_flags = havoc_flags} | PreserveFlags -> s2 in assert (overflow s1_new.ms_flags == overflow s2_new.ms_flags); assert (cf s1_new.ms_flags == cf s2_new.ms_flags); assert (equiv_states s1_new s2_new); let os1 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s1_new) vs1 in let os2 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s2_new) vs2 in match vs1 with | None -> () | Some vs -> lemma_instr_write_outputs_equiv_states outs args vs oprs s1 s1_new s2 s2_new #push-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" (* REVIEW: This proof is INSANELY annoying to deal with due to the [Pop]. TODO: Figure out why it is slowing down so much. It practically brings F* to a standstill even when editing, and it acts worse during an interactive proof. *) let lemma_machine_eval_ins_st_equiv_states (i : ins) (s1 s2 : machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( equiv_states (run (machine_eval_ins_st i) s1) (run (machine_eval_ins_st i) s2))) = let s1_orig, s2_orig = s1, s2 in let s1_final = run (machine_eval_ins_st i) s1 in let s2_final = run (machine_eval_ins_st i) s2 in match i with | Instr it oprs ann -> lemma_eval_instr_equiv_states it oprs ann s1 s2 | Push _ _ -> assert_spinoff (equiv_states_ext s1_final s2_final) | Pop dst t -> let stack_op = OStack (MReg (Reg 0 rRsp) 0, t) in let s1 = proof_run s1 (check (valid_src_operand64_and_taint stack_op)) in let s2 = proof_run s2 (check (valid_src_operand64_and_taint stack_op)) in // assert (equiv_states s1 s2); let new_dst1 = eval_operand stack_op s1 in let new_dst2 = eval_operand stack_op s2 in // assert (new_dst1 == new_dst2); let new_rsp1 = (eval_reg_64 rRsp s1 + 8) % pow2_64 in let new_rsp2 = (eval_reg_64 rRsp s2 + 8) % pow2_64 in // assert (new_rsp1 == new_rsp2); let s1 = proof_run s1 (update_operand64_preserve_flags dst new_dst1) in let s2 = proof_run s2 (update_operand64_preserve_flags dst new_dst2) in assert (equiv_states_ext s1 s2); let s1 = proof_run s1 (free_stack (new_rsp1 - 8) new_rsp1) in let s2 = proof_run s2 (free_stack (new_rsp2 - 8) new_rsp2) in // assert (equiv_states s1 s2); let s1 = proof_run s1 (update_rsp new_rsp1) in let s2 = proof_run s2 (update_rsp new_rsp2) in assert (equiv_states_ext s1 s2); assert_spinoff (equiv_states s1_final s2_final) | Alloc _ -> assert_spinoff (equiv_states_ext s1_final s2_final) | Dealloc _ -> assert_spinoff (equiv_states_ext s1_final s2_final) #pop-options let lemma_eval_ins_equiv_states (i : ins) (s1 s2 : machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( equiv_states (machine_eval_ins i s1) (machine_eval_ins i s2))) = lemma_machine_eval_ins_st_equiv_states i s1 s2
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s: Vale.X64.Machine_Semantics_s.machine_state -> Vale.X64.Machine_Semantics_s.machine_state
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.Mkmachine_state", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint", "Prims.Nil", "Vale.X64.Machine_s.observation" ]
[]
false
false
false
true
false
let filt_state (s: machine_state) =
{ s with ms_trace = [] }
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.erroring_option_state
val erroring_option_state : s: FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool
let erroring_option_state (s:option machine_state) = match s with | None -> true | Some s -> not (s.ms_ok)
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 178, "start_col": 0, "start_line": 175 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same. let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint) (** Same as [equiv_states] but uses extensionality to "think harder"; useful at lower-level details of the proof. *) let equiv_states_ext (s1 s2 : machine_state) : GTot Type0 = let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2) (** A weaker version of [equiv_states] that makes all non-ok states equivalent. Since non-ok states indicate something "gone-wrong" in execution, we can safely say that the rest of the state is irrelevant. *) let equiv_states_or_both_not_ok (s1 s2:machine_state) = (equiv_states s1 s2) \/ ((not s1.ms_ok) /\ (not s2.ms_ok)) (** Convenience wrapper around [equiv_states] *) unfold let equiv_ostates (s1 s2 : option machine_state) : GTot Type0 = (Some? s1 = Some? s2) /\ (Some? s1 ==> (equiv_states (Some?.v s1) (Some?.v s2))) (** An [option state] is said to be erroring if it is either [None] or if it is [Some] but is not ok. *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s: FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.op_Negation", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Prims.bool" ]
[]
false
false
false
true
false
let erroring_option_state (s: option machine_state) =
match s with | None -> true | Some s -> not (s.ms_ok)
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.lemma_ins_exchange_allowed_symmetric
val lemma_ins_exchange_allowed_symmetric (i1 i2: ins) : Lemma (requires (!!(ins_exchange_allowed i1 i2))) (ensures (!!(ins_exchange_allowed i2 i1)))
val lemma_ins_exchange_allowed_symmetric (i1 i2: ins) : Lemma (requires (!!(ins_exchange_allowed i1 i2))) (ensures (!!(ins_exchange_allowed i2 i1)))
let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 133, "start_col": 0, "start_line": 124 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
i1: Vale.X64.Machine_Semantics_s.ins -> i2: Vale.X64.Machine_Semantics_s.ins -> FStar.Pervasives.Lemma (requires !!(Vale.Transformers.InstructionReorder.ins_exchange_allowed i1 i2)) (ensures !!(Vale.Transformers.InstructionReorder.ins_exchange_allowed i2 i1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.Transformers.BoundedInstructionEffects.rw_set", "Vale.Transformers.Locations.locations", "Vale.Transformers.BoundedInstructionEffects.locations_with_values", "Vale.Transformers.InstructionReorder.lemma_write_exchange_allowed_symmetric", "Prims.unit", "FStar.Pervasives.Native.tuple3", "Prims.list", "Vale.Transformers.Locations.location", "FStar.Pervasives.Native.Mktuple3", "Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads", "Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes", "Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins", "Prims.b2t", "Vale.Def.PossiblyMonad.op_Bang_Bang", "Vale.Transformers.InstructionReorder.ins_exchange_allowed", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_ins_exchange_allowed_symmetric (i1 i2: ins) : Lemma (requires (!!(ins_exchange_allowed i1 i2))) (ensures (!!(ins_exchange_allowed i2 i1))) =
let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2
false
Vale.Transformers.InstructionReorder.fst
Vale.Transformers.InstructionReorder.commutes
val commutes (s: machine_state) (f1 f2: st unit) : GTot Type0
val commutes (s: machine_state) (f1 f2: st unit) : GTot Type0
let commutes (s:machine_state) (f1 f2:st unit) : GTot Type0 = equiv_states_or_both_not_ok (run2 f1 f2 s) (run2 f2 f1 s)
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 563, "start_col": 0, "start_line": 560 }
(** This module defines a transformer that performs safe instruction reordering. Example: The following set of instructions can be reordered in any order without any observable change in behavior: mov rax, 10 mov rbx, 3 Usage: Actual vale-tool or user-facing code should probably use the even nicer interface provided by the [Vale.Transformers.Transform] module. To use this module, you need to generate a [transformation_hints] object (a nice default is provided in this module via [find_transformation_hints], but users of this module can write their own, without needing to change any proofs), that can then be applied to a [codes] object (say [c1]) via [perform_reordering_with_hints] which tells you if this is a safe reordering, and if so, it produces the transformed [codes] object. If it is not considered to be safe, then the transformer gives a (human-readable) reason for why it doesn't consider it a safe reordering. If the transformation is safe and was indeed performed, then you can use [lemma_perform_reordering_with_hints] to reason about the reordered code having semantically equivalent behavior as the untransformed code. *) module Vale.Transformers.InstructionReorder /// Open all the relevant modules open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad open Vale.Transformers.Locations open Vale.Transformers.BoundedInstructionEffects module L = FStar.List.Tot /// Some convenience functions let rec locations_of_locations_with_values (lv:locations_with_values) : locations = match lv with | [] -> [] | (|l,v|) :: lv -> l :: locations_of_locations_with_values lv /// Given two read/write sets corresponding to two neighboring /// instructions, we can say whether exchanging those two instructions /// should be allowed. let write_same_constants (c1 c2:locations_with_values) : pbool = for_all (fun (x1:location_with_value) -> for_all (fun (x2:location_with_value) -> let (| l1, v1 |) = x1 in let (| l2, v2 |) = x2 in (if l1 = l2 then v1 = v2 else true) /- "not writing same constants" ) c2 ) c1 let aux_write_exchange_allowed (w2:locations) (c1 c2:locations_with_values) (x:location) : pbool = let cv1, cv2 = locations_of_locations_with_values c1, locations_of_locations_with_values c2 in (disjoint_location_from_locations x w2) ||. ((x `L.mem` cv1 && x `L.mem` cv2) /- "non constant write") let write_exchange_allowed (w1 w2:locations) (c1 c2:locations_with_values) : pbool = write_same_constants c1 c2 &&. for_all (aux_write_exchange_allowed w2 c1 c2) w1 &&. (* REVIEW: Just to make the symmetry proof easier, we write the other way around too. However, this makes things not as fast as they _could_ be. *) for_all (aux_write_exchange_allowed w1 c2 c1) w2 let rw_exchange_allowed (rw1 rw2 : rw_set) : pbool = let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in (disjoint_locations r1 w2 /+< "read set of 1st not disjoint from write set of 2nd because ") &&. (disjoint_locations r2 w1 /+< "read set of 2nd not disjoint from write set of 1st because ") &&. (write_exchange_allowed w1 w2 c1 c2 /+< "write sets not disjoint because ") let ins_exchange_allowed (i1 i2 : ins) : pbool = ( match i1, i2 with | Instr _ _ _, Instr _ _ _ -> (rw_exchange_allowed (rw_set_of_ins i1) (rw_set_of_ins i2)) | _, _ -> ffalse "non-generic instructions: conservatively disallowed exchange" ) /+> normal (" for instructions " ^ print_ins i1 gcc ^ " and " ^ print_ins i2 gcc) let rec lemma_write_same_constants_symmetric (c1 c2:locations_with_values) : Lemma (ensures (!!(write_same_constants c1 c2) = !!(write_same_constants c2 c1))) = match c1, c2 with | [], [] -> () | x :: xs, [] -> lemma_write_same_constants_symmetric xs [] | [], y :: ys -> lemma_write_same_constants_symmetric [] ys | x :: xs, y :: ys -> lemma_write_same_constants_symmetric c1 ys; lemma_write_same_constants_symmetric xs c2; lemma_write_same_constants_symmetric xs ys let lemma_write_exchange_allowed_symmetric (w1 w2:locations) (c1 c2:locations_with_values) : Lemma (ensures (!!(write_exchange_allowed w1 w2 c1 c2) = !!(write_exchange_allowed w2 w1 c2 c1))) = lemma_write_same_constants_symmetric c1 c2 let lemma_ins_exchange_allowed_symmetric (i1 i2 : ins) : Lemma (requires ( !!(ins_exchange_allowed i1 i2))) (ensures ( !!(ins_exchange_allowed i2 i1))) = let rw1, rw2 = rw_set_of_ins i1, rw_set_of_ins i2 in let r1, w1, c1 = rw1.loc_reads, rw1.loc_writes, rw1.loc_constant_writes in let r2, w2, c2 = rw2.loc_reads, rw2.loc_writes, rw2.loc_constant_writes in lemma_write_exchange_allowed_symmetric w1 w2 c1 c2 /// First, we must define what it means for two states to be /// equivalent. Here, we basically say they must be exactly the same. let equiv_states (s1 s2 : machine_state) : GTot Type0 = (s1.ms_ok == s2.ms_ok) /\ (s1.ms_regs == s2.ms_regs) /\ (cf s1.ms_flags = cf s2.ms_flags) /\ (overflow s1.ms_flags = overflow s2.ms_flags) /\ (s1.ms_heap == s2.ms_heap) /\ (s1.ms_stack == s2.ms_stack) /\ (s1.ms_stackTaint == s2.ms_stackTaint) (** Same as [equiv_states] but uses extensionality to "think harder"; useful at lower-level details of the proof. *) let equiv_states_ext (s1 s2 : machine_state) : GTot Type0 = let open FStar.FunctionalExtensionality in (feq s1.ms_regs s2.ms_regs) /\ (s1.ms_heap == s2.ms_heap) /\ (Map.equal s1.ms_stack.stack_mem s2.ms_stack.stack_mem) /\ (Map.equal s1.ms_stackTaint s2.ms_stackTaint) /\ (equiv_states s1 s2) (** A weaker version of [equiv_states] that makes all non-ok states equivalent. Since non-ok states indicate something "gone-wrong" in execution, we can safely say that the rest of the state is irrelevant. *) let equiv_states_or_both_not_ok (s1 s2:machine_state) = (equiv_states s1 s2) \/ ((not s1.ms_ok) /\ (not s2.ms_ok)) (** Convenience wrapper around [equiv_states] *) unfold let equiv_ostates (s1 s2 : option machine_state) : GTot Type0 = (Some? s1 = Some? s2) /\ (Some? s1 ==> (equiv_states (Some?.v s1) (Some?.v s2))) (** An [option state] is said to be erroring if it is either [None] or if it is [Some] but is not ok. *) unfold let erroring_option_state (s:option machine_state) = match s with | None -> true | Some s -> not (s.ms_ok) (** [equiv_option_states s1 s2] means that [s1] and [s2] are equivalent [option machine_state]s iff both have same erroring behavior and if they are non-erroring, they are [equiv_states]. *) unfold let equiv_option_states (s1 s2:option machine_state) = (erroring_option_state s1 == erroring_option_state s2) /\ (not (erroring_option_state s1) ==> equiv_states (Some?.v s1) (Some?.v s2)) /// If evaluation starts from a set of equivalent states, and the /// exact same thing is evaluated, then the final states are still /// equivalent. unfold let proof_run (s:machine_state) (f:st unit) : machine_state = let (), s1 = f s in { s1 with ms_ok = s1.ms_ok && s.ms_ok } let rec lemma_instr_apply_eval_args_equiv_states (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( (instr_apply_eval_args outs args f oprs s1) == (instr_apply_eval_args outs args f oprs s2))) = match args with | [] -> () | i :: args -> let (v, oprs) : option (instr_val_t i) & _ = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_instr_apply_eval_args_equiv_states outs args (f v) oprs s1 s2 #push-options "--z3rlimit 10" let rec lemma_instr_apply_eval_inouts_equiv_states (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( (instr_apply_eval_inouts outs inouts args f oprs s1) == (instr_apply_eval_inouts outs inouts args f oprs s2))) = match inouts with | [] -> lemma_instr_apply_eval_args_equiv_states outs args f oprs s1 s2 | (Out, i) :: inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_instr_apply_eval_inouts_equiv_states outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> let (v, oprs) : option (instr_val_t i) & _ = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_instr_apply_eval_inouts_equiv_states outs inouts args (f v) oprs s1 s2 #pop-options #push-options "--z3rlimit 10 --max_fuel 1 --max_ifuel 0" let lemma_instr_write_output_implicit_equiv_states (i:instr_operand_implicit) (v:instr_val_t (IOpIm i)) (s_orig1 s1 s_orig2 s2:machine_state) : Lemma (requires ( (equiv_states s_orig1 s_orig2) /\ (equiv_states s1 s2))) (ensures ( (equiv_states (instr_write_output_implicit i v s_orig1 s1) (instr_write_output_implicit i v s_orig2 s2)))) = let snew1, snew2 = (instr_write_output_implicit i v s_orig1 s1), (instr_write_output_implicit i v s_orig2 s2) in assert (equiv_states_ext snew1 snew2) (* OBSERVE *) let lemma_instr_write_output_explicit_equiv_states (i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i) (s_orig1 s1 s_orig2 s2:machine_state) : Lemma (requires ( (equiv_states s_orig1 s_orig2) /\ (equiv_states s1 s2))) (ensures ( (equiv_states (instr_write_output_explicit i v o s_orig1 s1) (instr_write_output_explicit i v o s_orig2 s2)))) = let snew1, snew2 = (instr_write_output_explicit i v o s_orig1 s1), (instr_write_output_explicit i v o s_orig2 s2) in assert (equiv_states_ext snew1 snew2) (* OBSERVE *) #pop-options let rec lemma_instr_write_outputs_equiv_states (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig1 s1:machine_state) (s_orig2 s2:machine_state) : Lemma (requires ( (equiv_states s_orig1 s_orig2) /\ (equiv_states s1 s2))) (ensures ( (equiv_states (instr_write_outputs outs args vs oprs s_orig1 s1) (instr_write_outputs outs args vs oprs s_orig2 s2)))) = match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in lemma_instr_write_output_explicit_equiv_states i v (fst oprs) s_orig1 s1 s_orig2 s2; let s1 = instr_write_output_explicit i v (fst oprs) s_orig1 s1 in let s2 = instr_write_output_explicit i v (fst oprs) s_orig2 s2 in lemma_instr_write_outputs_equiv_states outs args vs (snd oprs) s_orig1 s1 s_orig2 s2 | IOpIm i -> lemma_instr_write_output_implicit_equiv_states i v s_orig1 s1 s_orig2 s2; let s1 = instr_write_output_implicit i v s_orig1 s1 in let s2 = instr_write_output_implicit i v s_orig2 s2 in lemma_instr_write_outputs_equiv_states outs args vs (coerce oprs) s_orig1 s1 s_orig2 s2 ) let lemma_eval_instr_equiv_states (it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it) (s1 s2:machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( equiv_ostates (eval_instr it oprs ann s1) (eval_instr it oprs ann s2))) = let InstrTypeRecord #outs #args #havoc_flags' i = it in let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in lemma_instr_apply_eval_inouts_equiv_states outs outs args (instr_eval i) oprs s1 s2; assert (vs1 == vs2); let s1_new = match havoc_flags' with | HavocFlags -> {s1 with ms_flags = havoc_flags} | PreserveFlags -> s1 in let s2_new = match havoc_flags' with | HavocFlags -> {s2 with ms_flags = havoc_flags} | PreserveFlags -> s2 in assert (overflow s1_new.ms_flags == overflow s2_new.ms_flags); assert (cf s1_new.ms_flags == cf s2_new.ms_flags); assert (equiv_states s1_new s2_new); let os1 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s1_new) vs1 in let os2 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s2_new) vs2 in match vs1 with | None -> () | Some vs -> lemma_instr_write_outputs_equiv_states outs args vs oprs s1 s1_new s2 s2_new #push-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" (* REVIEW: This proof is INSANELY annoying to deal with due to the [Pop]. TODO: Figure out why it is slowing down so much. It practically brings F* to a standstill even when editing, and it acts worse during an interactive proof. *) let lemma_machine_eval_ins_st_equiv_states (i : ins) (s1 s2 : machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( equiv_states (run (machine_eval_ins_st i) s1) (run (machine_eval_ins_st i) s2))) = let s1_orig, s2_orig = s1, s2 in let s1_final = run (machine_eval_ins_st i) s1 in let s2_final = run (machine_eval_ins_st i) s2 in match i with | Instr it oprs ann -> lemma_eval_instr_equiv_states it oprs ann s1 s2 | Push _ _ -> assert_spinoff (equiv_states_ext s1_final s2_final) | Pop dst t -> let stack_op = OStack (MReg (Reg 0 rRsp) 0, t) in let s1 = proof_run s1 (check (valid_src_operand64_and_taint stack_op)) in let s2 = proof_run s2 (check (valid_src_operand64_and_taint stack_op)) in // assert (equiv_states s1 s2); let new_dst1 = eval_operand stack_op s1 in let new_dst2 = eval_operand stack_op s2 in // assert (new_dst1 == new_dst2); let new_rsp1 = (eval_reg_64 rRsp s1 + 8) % pow2_64 in let new_rsp2 = (eval_reg_64 rRsp s2 + 8) % pow2_64 in // assert (new_rsp1 == new_rsp2); let s1 = proof_run s1 (update_operand64_preserve_flags dst new_dst1) in let s2 = proof_run s2 (update_operand64_preserve_flags dst new_dst2) in assert (equiv_states_ext s1 s2); let s1 = proof_run s1 (free_stack (new_rsp1 - 8) new_rsp1) in let s2 = proof_run s2 (free_stack (new_rsp2 - 8) new_rsp2) in // assert (equiv_states s1 s2); let s1 = proof_run s1 (update_rsp new_rsp1) in let s2 = proof_run s2 (update_rsp new_rsp2) in assert (equiv_states_ext s1 s2); assert_spinoff (equiv_states s1_final s2_final) | Alloc _ -> assert_spinoff (equiv_states_ext s1_final s2_final) | Dealloc _ -> assert_spinoff (equiv_states_ext s1_final s2_final) #pop-options let lemma_eval_ins_equiv_states (i : ins) (s1 s2 : machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( equiv_states (machine_eval_ins i s1) (machine_eval_ins i s2))) = lemma_machine_eval_ins_st_equiv_states i s1 s2 (** Filter out observation related stuff from the state. *) let filt_state (s:machine_state) = { s with ms_trace = [] } #push-options "--z3rlimit 10 --max_fuel 1 --max_ifuel 1" let rec lemma_eval_code_equiv_states (c : code) (fuel:nat) (s1 s2 : machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( let s1'', s2'' = machine_eval_code c fuel s1, machine_eval_code c fuel s2 in equiv_ostates s1'' s2'')) (decreases %[fuel; c]) = match c with | Ins ins -> reveal_opaque (`%machine_eval_code_ins) machine_eval_code_ins; lemma_eval_ins_equiv_states ins (filt_state s1) (filt_state s2) | Block l -> lemma_eval_codes_equiv_states l fuel s1 s2 | IfElse ifCond ifTrue ifFalse -> reveal_opaque (`%valid_ocmp_opaque) valid_ocmp_opaque; reveal_opaque (`%eval_ocmp_opaque) eval_ocmp_opaque; let (s1', b1) = machine_eval_ocmp s1 ifCond in let (s2', b2) = machine_eval_ocmp s2 ifCond in assert (b1 == b2); assert (equiv_states s1' s2'); if b1 then ( lemma_eval_code_equiv_states ifTrue fuel s1' s2' ) else ( lemma_eval_code_equiv_states ifFalse fuel s1' s2' ) | While cond body -> lemma_eval_while_equiv_states cond body fuel s1 s2 and lemma_eval_codes_equiv_states (cs : codes) (fuel:nat) (s1 s2 : machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( let s1'', s2'' = machine_eval_codes cs fuel s1, machine_eval_codes cs fuel s2 in equiv_ostates s1'' s2'')) (decreases %[fuel; cs]) = match cs with | [] -> () | c :: cs -> lemma_eval_code_equiv_states c fuel s1 s2; let s1'', s2'' = machine_eval_code c fuel s1, machine_eval_code c fuel s2 in match s1'' with | None -> () | _ -> let Some s1, Some s2 = s1'', s2'' in lemma_eval_codes_equiv_states cs fuel s1 s2 and lemma_eval_while_equiv_states (cond:ocmp) (body:code) (fuel:nat) (s1 s2:machine_state) : Lemma (requires (equiv_states s1 s2)) (ensures ( equiv_ostates (machine_eval_while cond body fuel s1) (machine_eval_while cond body fuel s2))) (decreases %[fuel; body]) = if fuel = 0 then () else ( reveal_opaque (`%valid_ocmp_opaque) valid_ocmp_opaque; reveal_opaque (`%eval_ocmp_opaque) eval_ocmp_opaque; let (s1, b1) = machine_eval_ocmp s1 cond in let (s2, b2) = machine_eval_ocmp s2 cond in assert (equiv_states s1 s2); assert (b1 == b2); if not b1 then () else ( assert (equiv_states s1 s2); let s_opt1 = machine_eval_code body (fuel - 1) s1 in let s_opt2 = machine_eval_code body (fuel - 1) s2 in lemma_eval_code_equiv_states body (fuel - 1) s1 s2; assert (equiv_ostates s_opt1 s_opt2); match s_opt1 with | None -> () | Some _ -> let Some s1, Some s2 = s_opt1, s_opt2 in if s1.ms_ok then ( lemma_eval_while_equiv_states cond body (fuel - 1) s1 s2 ) else () ) ) #pop-options /// If an exchange is allowed between two instructions based off of /// their read/write sets, then both orderings of the two instructions /// behave exactly the same, as per the previously defined /// [equiv_states] relation. /// /// Note that we require (for the overall proof) a notion of the /// following: /// /// s1 ===== s2 Key: /// | | /// . . + s1, s2, ... : machine_states /// . f1 . f2 + f1, f2 : some function from a /// . . machine_state to a /// | | machine_state /// V V + ===== : equiv_states /// s1' ===== s2' /// /// However, proving with the [equiv_states s1 s2] as part of the /// preconditions requires come complex wrangling and thinking about /// how different states [s1] and [s2] evolve. In particular, we'd /// need to show and write something similar _every_ step of the /// execution of [f1] and [f2]. Instead, we decompose the above /// diagram into the following: /// /// /// s1 ===== s2 /// / \ \ /// . . . /// . f1 . f2 . f2 /// . . . /// / \ \ /// V V V /// s1' ===== s2''===== s2' /// /// /// We now have the ability to decompose the left "triangular" portion /// which is similar to the rectangular diagram above, except the /// issue of having to manage both [s1] and [s2] is mitigated. Next, /// if we look at the right "parallelogram" portion of the diagram, we /// see that this is just the same as saying "running [f2] on /// [equiv_states] leads to [equiv_states]" which is something that is /// easier to prove. /// /// All the parallelogram proofs have already been completed by this /// point in the file, so only the triangular portions remain (and the /// one proof that links the two up into a single diagram as above). unfold let run2 (f1 f2:st unit) (s:machine_state) : machine_state = let open Vale.X64.Machine_Semantics_s in run (f1;* f2;* return ()) s
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.Locations.fsti.checked", "Vale.Transformers.BoundedInstructionEffects.fsti.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Option.fst.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.InstructionReorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Transformers.BoundedInstructionEffects", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Locations", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s: Vale.X64.Machine_Semantics_s.machine_state -> f1: Vale.X64.Machine_Semantics_s.st Prims.unit -> f2: Vale.X64.Machine_Semantics_s.st Prims.unit -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.st", "Prims.unit", "Vale.Transformers.InstructionReorder.equiv_states_or_both_not_ok", "Vale.Transformers.InstructionReorder.run2" ]
[]
false
false
false
false
true
let commutes (s: machine_state) (f1 f2: st unit) : GTot Type0 =
equiv_states_or_both_not_ok (run2 f1 f2 s) (run2 f2 f1 s)
false